码迷,mamicode.com
首页 > 数据库 > 详细

sql server 行列互转

时间:2017-03-21 10:38:06      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:arc   nbsp   create   har   form   creat   arch   mat   from   

create database Inter_Transformation
go
create table Tb
(
Uname varchar(30),
Course varchar(30),
Fraction int
)
go
insert into tb values(‘张三‘,‘语文‘,74)

insert into tb values(‘张三‘,‘数学‘,83)

insert into tb values(‘张三‘,‘物理‘,93)

insert into tb values(‘李四‘,‘语文‘,74)

insert into tb values(‘李四‘,‘数学‘,84)

insert into tb values(‘李四‘,‘物理‘,94)

insert into tb values(‘王五‘,‘语文‘,null)

insert into tb values(‘王五‘,‘数学‘,84)

insert into tb values(‘王五‘,‘物理‘,94)

go

select * from Tb

go

select Uname,
MAX(case Course when‘语文‘then Fraction else 0 end)语文,
MAX(case Course when‘数学‘then Fraction else 0 end)数学,
MAX(case Course when‘物理‘then Fraction else 0 end)物理
from tb
group by Uname

 

sql server 行列互转

标签:arc   nbsp   create   har   form   creat   arch   mat   from   

原文地址:http://www.cnblogs.com/gsh0921/p/6592795.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!