create table tb3
(
a varchar(20),
b varchar(20)
)
insert into tb3(a,b) values('2013-10-9','正');
insert into tb3(a,b) values ('2013-10-9','正');
insert into tb3(a,b) values ('2013-10-9','负');
insert into tb3(a,b) values ('2013-10-9','负');
insert into tb3(a,b) values ('2013-10-10','正');
insert into tb3(a,b) values ('2013-10-10','负');
insert into tb3(a,b) values ('2013-10-10','负');
SELECT * from tb3
select a,[正] AS A ,[负] AS B from
(select * from tb3) p
pivot
(
COUNT(b)
for b in (正,负)
) as pvt
select 时间,sum(case when xx='正' then 1 else 0 end),
sum(case when xx='负' then 1 else 0 end),
from 表
group by 时间
Select 日期,
SUM(case when 正负='正' then 1 else 0 end) as 胜利数,
SUM(case when 正负='负' then 1 else 0 end) as 失败数
From 表 Group by 日期