读书人

SQL话语 帮帮忙.

发布时间: 2013-10-15 16:47:37 作者: rapoo

SQL语句 帮帮忙.......
SQL话语  帮帮忙. sql
[解决办法]

create table #tb([day] varchar(10),result varchar(10))
insert into #tb
select '2013-05-09','胜'
union all select '2013-05-09','胜'
union all select '2013-05-09','负'
union all select '2013-05-09','负'
union all select '2013-05-10','胜'
union all select '2013-05-10','负'
union all select '2013-05-10','负'


select [day] as 日期,胜=sum(case when result='胜' then 1 else 0 end)
,负=sum(case when result='负' then 1 else 0 end)
from #tb
group by [day]

/*
日期 胜 负
---------------------------
2013-05-0922
2013-05-1012
*/

读书人网 >SQL Server

热点推荐