您的位置:首页 > 数据库

sql行列互换问题

2008-01-14 10:34 274 查看
create table tb_student --create table
(
sname varchar(20),
object varchar (20),
score int
)
go
insert tb_student select 'a','EN',89 union all --add data to table
select 'a','CH',78 union all
select 'a','HO',99 union all
select 'b','EN',34 union all
select 'b','CH',88 union all
select 'b','HO',0
go
select * from tb_student --view data sourse

select sname,英语=sum(case
object when 'EN' then score
end),语文=sum(case
object when 'CH' then score
end),数学=sum(case
object when 'HO' then score
end)
from tb_student group by sname
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: