读书人

SQL语句查询,该怎么处理

发布时间: 2012-03-22 17:43:57 作者: rapoo

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]

读书人网 >.NET Framework

热点推荐