http://www.cnblogs.com/NewLand/archive/2007/09/03/880540.html
--行列互换
Use tempdb
Go
Create table test ( [name] char(10), km char(10) , cj int )
Go
--初始化数据
insert into test values('张三','语文',80)
insert into test values('张三','数学',86)
insert into test values('张三','英语',75)
insert into test values('李四','语文',78)
insert into test values('李四','数学',85)
insert into test values('李四','英语',78)
Go
select name,sum(case km when '语文' then cj end) as 语文,
sum(case km when '数学' then cj end) as 数学,
sum(case km when '英语' then cj end) as 英语
from test
group by name
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!http://www.cnblogs.com/sunshine-anycall/archive/2009/03/22/1418758.html