SQL语句查询
某表内容如下:
date                      result
2005-05-09                  胜
2005-05-09                  胜
2005-05-09                  负
2005-05-09                  负
2005-05-10                  胜
2005-05-10                  负
2005-05-10                  负
如果要生成下列结果,该如何写sql语句?
                       胜      负
2005-05-09            2       2
2005-05-10            1       2
------解决方案-------------------- 自行Google
sql纵表转横表
------解决方案-------------------- SQL code
select [date] as 日期,count(case when result='胜' then 1 end) as 胜,count(case when result='负' then 1 end) as 负 from T group by [date];
------解决方案--------------------  探讨  SQL code select [date] as 日期,count(case when result='胜' then 1 end) as 胜,count(case when result='负' then 1 end) as 负 from T group by [date]; 
------解决方案--------------------  SQL行列转换
------解决方案--------------------  引用: select [date] as 日期,count(case when result='胜' then 1 end) as 胜,count(case when result='负' then 1 end) as 负 from T group by [date]; [/Quote]