select '小明' as name,'數學' as subjects,'100' as scores
union
select '小明' as name,'國文' as subjects,'95' as scores
union
select '小明' as name,'英語' as subjects,'90' as scores
union
select '小張' as name,'數學' as subjects,'100' as scores
union
select '小張' as name,'國文' as subjects,'98' as scores
union
select '小張' as name,'英語' as subjects,'99' as scores
select * from
(select '小明' as name,'數學' as subjects,100 as scores
union
select '小明' as name,'國文' as subjects,95 as scores
union
select '小明' as name,'英語' as subjects,90 as scores
union
select '小張' as name,'數學' as subjects,100 as scores
union
select '小張' as name,'國文' as subjects,98 as scores
union
select '小張' as name,'英語' as subjects,99 as scores) as tabs
pivot (
sum(scores)
for subjects in ([數學],[國文],[英語])
) as 分數