합계를 가로로 출력하기(decode) - sum(decode(열, 행, 행 값) as 별명
예시)
select sum(decode(deptno, 10, sal, null)) as "10",
sum(decode(deptno, 20, sal, null)) as "20",
sum(decode(deptno, 30, sal, null)) as "30"
from emp
합계를 가로로 출력하기(pivot) - select * 또는 행 이름 from (서브 쿼리) pivot ( sum for 열 이름 in 행 이름)
예시1)
select *
from (select deptno, sal from emp)
pivot (sum(sal) for deptno in (10, 20, 30))
예시2)
select *
from (select job, sal from emp)
pivot (sum(sal) for job in ('PRESIDENT', 'MANAGER', 'SALESEMAN', 'CLERK', 'ANALYST'))
열을 행으로 출력하기 - unpivot