我想根据一个表里的某个字段的值分别统计(按日期统计)出来的结果在同一个结果集中显示,请问如何做?

msn365 2005-07-29 09:30:13
我想根据一个表里的某个字段的值分别统计(按日期统计)出来的结果在同一个结果集中显示,请问如何做?

例如,根据字段stat=1和=2分别按时间统计的结果:
date count1(stat=1) count2(stat=2)
--------------------------------------------
2005-7-1 1 4
2005-7-2 8 0
2005-7-3 2 9
...... .... .....
...全文
94 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyit2004 2005-07-29
  • 打赏
  • 举报
回复
select
[term],
sum(case when stat=1 then 1 else 0 end) as count1(stat=1) ,
sum(case when stat=2 then 1 else 0 end) as count2(stat=2)
from
表名
group by
[term]
子陌红尘 2005-07-29
  • 打赏
  • 举报
回复
select
[date],
count1 = sum(case when stat=1 then 1 else 0 end),
count2 = sum(case when stat=2 then 1 else 0 end)
from

group by
[date]
order by
[date]

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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