insert into tb1 values('2005-05-09','胜')
insert into tb1 values('2005-05-09','胜')
insert into tb1 values('2005-05-09','负')
insert into tb1 values('2005-05-09','负')
insert into tb1 values('2005-05-10','负')
insert into tb1 values('2005-05-10','负')
insert into tb1 values('2005-05-10','胜')
select rq,jg,count(jg) as cs into #t
from tb1
group by rq,jg
order by rq
select rq,sum(case jg when '胜' then cs else 0 end) as '胜',sum(case jg when '负' then cs else 0 end ) as '负'
from #t
group by rq
drop table #t
rq 胜 负
------------------------------------------------------ ----------- -----------
2005-05-09 00:00:00.000 2 2
2005-05-10 00:00:00.000 1 2
本文通过具体实例演示如何使用SQL进行复杂的数据统计与分组查询,包括插入数据、创建临时表、分组统计以及最终结果的汇总展示。
950

被折叠的 条评论
为什么被折叠?



