日期:2014-05-17  浏览次数:20641 次

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
*/