本帖最后由 王毅 于 2013-3-11 23:34 编辑
创建一个新表 table9
create table table9 (date datetime,name nvarchar(10),score nvarchar(10))
insert into table9 (date,name,score)values('2008-08-08',N'拜仁',N'胜')
insert into table9 (date,name,score)values('2008-08-09',N'奇才',N'胜')
insert into table9 (date,name,score)values('2008-08-10',N'湖人',N'负')
insert into table9 (date,name,score)values('2008-08-11',N'拜仁',N'负')
insert into table9 (date,name,score)values('2008-08-12',N'奇才',N'胜')
题目要求
select name,
sum(case ---------在score 写在when的后面 进行比较
when score=N'胜' then 1
else 0
end)as 胜,
sum(case
when score=N'负'then 1
else 0
end)as 负 from table9
group by name 可以做出图片中的表格
写为
select name,
{case score -- 把score 单独写在case 后面
when N'胜' then 1
else 0
end
}as 胜利,
{case score
when N'负' then 1
else 0
end
}as 失败,
from table9
group by name ----------系统错误提示是关键字 'case' 附近有语法错误。但是没找到 ,大家帮忙给看下吧
|