サブクエリと集計だけでこれを行う方法は次のとおりです:
select name,
sum(case when fy = 2014 then x end) as "2014",
sum(case when fy = 2015 then x end) as "2015",
sum(case when fy = 2016 then x end) as "2016"
from (select fy,
(case when n.n = 1 then 'x1'
when n.n = 2 then 'x2'
when n.n = 3 then 'x3'
when n.n = 4 then 'x4'
end) as name,
(case when n.n = 1 then x1
when n.n = 2 then x2
when n.n = 3 then x3
when n.n = 4 then x4
end) as x
from temp_table cross join
(select 1 as n from dual union all
select 2 from dual union all
select 3 from dual union all
select 4 from dual
) n
) t
group by name;
pivot
も使用できます 、しかしこれはOracle SQLに最近追加されたものなので、私はこの方法を使用する傾向があります.