--数据表中行列转换
create table stuStore
(
stuNum int,
stuClass varchar(20),
stuStores int
)--drop table stuStore
insert into stuStore values(1,'语文',100);
insert into stuStore values(1,'数学',56);
insert into stuStore values(2,'英语',90);
insert into stuStore values(2,'数学',97);
--select * from stuStore
--查询
select stuNum,MAX(case when stuClass='语文' then stuStores else '' end) as '语文',
max(case when stuClass='数学' then stuStores else '' end) as '数学',
max(case when stuClass='英语' then stuStores else '' end) as '英语'
from stuStore group by stuNum
参考:
http://www.cnblogs.com/hongtao/archive/2010/11/16/1878630.html
create table stuStore
(
stuNum int,
stuClass varchar(20),
stuStores int
)--drop table stuStore
insert into stuStore values(1,'语文',100);
insert into stuStore values(1,'数学',56);
insert into stuStore values(2,'英语',90);
insert into stuStore values(2,'数学',97);
--select * from stuStore
--查询
select stuNum,MAX(case when stuClass='语文' then stuStores else '' end) as '语文',
max(case when stuClass='数学' then stuStores else '' end) as '数学',
max(case when stuClass='英语' then stuStores else '' end) as '英语'
from stuStore group by stuNum
参考:
http://www.cnblogs.com/hongtao/archive/2010/11/16/1878630.html