if exists(select * from sysobjects where name='T_Scores')
drop table T_Scores
create table T_Scores
(
Date datetime,
Name nvarchar(50),
Score nchar(1)
)
go
insert into T_Scores(Date,Name,Score)values('2008-8-8','拜仁','胜')
insert into T_Scores(Date,Name,Score)values('2008-8-9','奇才','胜')
insert into T_Scores(Date,Name,Score)values('2008-8-9','湖人','胜')
insert into T_Scores(Date,Name,Score)values('2008-8-10','拜仁','负')
insert into T_Scores(Date,Name,Score)values('2008-8-8','拜仁','负')
insert into T_Scores(Date,Name,Score)values('2008-8-12','奇才','胜')
go
select Name,
sum(
case Score
when N'胜' then 1
else 0
end
)as 胜,
sum(
case Score
when N'负' then 1
else 0
end) as 负
from T_Scores group by Name
|