–球队比分结果
create table score(
Id int identity(1,1) primary key ,
BallName varchar(50) not null,
PlayTime date not null default(getdate()),
Result varchar(2) not null
)
insert into score(BallName,Result)
select ‘勇士’,‘胜’ union
select ‘湖人’,‘负’ union
select ‘骑士’,'胜’union
select ‘勇士’,‘胜’ union
select ‘湖人’,‘负’ union
select ‘骑士’,'胜’union
select ‘马刺’,‘胜’ union
select ‘马刺’,‘负’ union
select ‘骑士’,'胜’union
select ‘勇士’,‘胜’ union
select ‘快船’,‘负’ union
select ‘骑士’,‘胜’
select ‘球队名称’=Ballname ,
胜=sum(case
when Result=‘胜’ then 1
else 0
end)
,负=sum(case
when Result=‘负’ then 1
else 0
end)
from score group by ballname