求各部门工资之和,要求横向显示
case when 写法:
select max(case when deptno = 10 then sal end)as "deptno10", max(case when deptno = 20 then sal end) as "deptno20", max(case when deptno = 30 then sal end) as "deptno30" from (select deptno,sum(sal) as sal from scott.emp group by deptno)
pivot 写法:
select * from (select deptno, sal from scott.emp ) pivot ( sum(sal) as sum_sal for (deptno) in (10,20,30) )