当前位置: 代码迷 >> Sql Server >> SQL话语 帮帮忙.
  详细解决方案

SQL话语 帮帮忙.

热度:407   发布时间:2016-04-24 20:14:07.0
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-09 2 2
2013-05-10 1 2
*/
  相关解决方案