原數據
目標數據:
---方法一
select t.name,
sum(decode(t.sub, '語文',score, 0)) as "語文",
sum(decode(t.sub, '數學',score, 0)) as "數學",
sum(decode(t.sub, '英語',score, 0)) as "英文"
from projects t
group by t.name;
--方法二
with tmp_tab as
(select t.name, t.sub,score from projects t)
select * from tmp_tab t pivot (sum(score) for sub in('語文','數學','英語'));