关闭

稠化报表然后行转列

67人阅读 评论(0) 收藏 举报
分类:
with t as
 (select deptno, job, sum(sal) sum_sal from emp group by deptno, job),
tt as
 (select distinct job from t),
ttt as (select b.deptno, a.job, sum_sal
  from tt a
  left join t b partition by (b.deptno)
    on a.job = b.job)
    select sum(case ttt.deptno when 10 then nvl(ttt.sum_sal,0) else 0 end ),sum(case ttt.deptno when 20 then nvl(ttt.sum_sal,0) else 0 end ),
    sum(case ttt.deptno when 30 then nvl(ttt.sum_sal,0) else 0 end ) from ttt 
    group by ttt.deptno
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9219次
    • 积分:340
    • 等级:
    • 排名:千里之外
    • 原创:22篇
    • 转载:25篇
    • 译文:0篇
    • 评论:1条
    最新评论