码迷,mamicode.com
首页 > 数据库 > 详细

数据库练习

时间:2017-07-24 17:31:42      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:com   group   dna   join   sel   group by   log   .com   结果   

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;

输出结果:

技术分享

 

数据库练习

标签:com   group   dna   join   sel   group by   log   .com   结果   

原文地址:http://www.cnblogs.com/baichaofeng123/p/7229690.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!