数据库练习

select
dept.dname,
ano "1000以下",
bno "1000~2000",
cno "2000~3000",
dno "3000以上"
from dept,
(select ano,bno,cno,nvl(d."3000以上",0) dno,g.deptno from
(select ano,bno,nvl(c."2000~3000",0) cno,f.deptno from
(select ano,nvl(b."1000~2000",0) bno,e.deptno from
(select nvl(a."1000以下",0) ano ,dept.deptno from dept
full join
(select count(sal) "1000以下" , deptno from emp where sal<1000 group by deptno) a
on dept.deptno = a.deptno) e
full join
(select count(ename) "1000~2000",deptno from emp where sal>=1000 and sal<2000 group by deptno) b
on e.deptno = b.deptno) f
full join
(select count(ename) "2000~3000",deptno from emp where sal>=2000 and sal<=3000 group by deptno) c
on f.deptno = c.deptno) g
full join
(select count(ename) "3000以上",deptno from emp where sal>3000group by deptno) d
on g.deptno = d.deptno) h
where dept.deptno = h.deptno;

输出结果:

 

posted on 2017-07-24 16:36  白超峰  阅读(108)  评论(0编辑  收藏  举报

导航