我的答案分两步
第一步:
select name,
(
case course
when N'语文' then score
else 0
end
) as 语文,
(
case course
when N'数学' then score
else 0
end
) as 数学 into ss
from T1
第二步:
select name,sum(数学)as 数学,sum(语文)as 语文
from ss
group by name
select [name] as 姓名,
sum(case [Subject]
when N'语文' then [Score]
else 0
end
)as 语文,
sum(case [Subject]
when N'数学' then [Score]
else 0
end)
as 数学
from T1
group by [name]