◆◆◆◆◆◆一个关于统计的简单的SQL问题,解决了马上给分,大虾们快帮忙啊◆◆◆◆◆◆

mingwj1980 2007-08-08 04:19:37
举个例子吧,假设一个关于统计广告的表table1是这样的
actiontime FLAG(0弹出,1点击)

如果我要按天统计每天的广告量,肯定是这样的
select day(actiontime), count(*) from table1 group by day(actiontime)

但是我希望第一例是天数,第二例是广告量,第三例是点击量(即FLAG为1)的量,这样的SQL语句能写出来么?

也就是在select day(actiontime), count(*) from table1 group by day(actiontime)的基础是增加一例能算是FLAG为1时的数量,谢谢大家了

...全文
137 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mingwj1980 2007-08-08
  • 打赏
  • 举报
回复
感谢楼上两位
dawugui 2007-08-08
  • 打赏
  • 举报
回复
select a.*,b.点击量 from
(select convert(varchar(10),actiontime,120) actiontime,count(*) as 广告量 from tb group by convert(varchar(10),actiontime,120)) a,
(select convert(varchar(10),actiontime,120) actiontime,count(*) as 点击量 from tb where FLAG=1 group by convert(varchar(10),actiontime,120)) b
where a.actiontime = b.actiontime
paoluo 2007-08-08
  • 打赏
  • 举报
回复
如果FLAG是Bit型,可以這麼投機下

select day(actiontime), count(*), SUM(Cast(FLAG As Int)) As 点击量 from table1 group by day(actiontime)
paoluo 2007-08-08
  • 打赏
  • 举报
回复
select day(actiontime), count(*), SUM(Case FLAG When 1 Then 1 Else 0 End) As 点击量 from table1 group by day(actiontime)

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧