<a href="http://www.cnblogs.com/newland/archive/2007/09/03/880540.html">http://www.cnblogs.com/newland/archive/2007/09/03/880540.html</a>
--行列互換
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)
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