表数据

 

2008-9-9 胜
2008-9-9 胜
2008-9-9 负
2008-9-10 胜
2008-9-10 负
2008-9-10 负

要查询出这个结果
          胜  负
2008-9-9  2    1
2008-9-10  1    2

 

SQL语句

 

select t1,胜=sum(case t2 when '胜' then 1 else 0 end),负=sum(case t2 when '负' then 1 else 0 end)
from ttt
group by t1

 

纳闷,工作这么多年,这样的使用还是头一次,以前从没这样统计过