Oracle基础练习题及答案(多表查询1)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

利用scott用户自带的四张表完成如下作业:
1.列出至少有一个员工的所有部门
select b.deptno,b.dname from emp a,dept b where a.deptno=b.deptno group by b.deptno,b.dname having count(*)>=1;
2.列出薪金比SMITH高的所有员工
select * from emp where sal>(select sal from emp where ename='SMITH');
3.列出所有员工的姓名及其直接上级领导的姓名
select a.ename,b.ename "leader" from emp a,emp b where a.mgr=b.empno;
4.列出受雇日期早于其直接上级的所有员工的编号,姓名,部门名称
select a.empno,a.ename,a.hiredate,c.dname from emp a,emp b,dept c where a.mgr=b.empno and a.deptno=c.deptno and a.hiredate<b.hiredate;
5.列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门
select b.dname,a.* from emp a,dept b where a.deptno(+)=b.deptno ;
6.列出所有CLERK(办事员)的姓名,及其部门名称,部门人数
select aa.ename,aa.job,bb.dname,
(select count(a.deptno) from emp a,dept b
where a.deptno=b.deptno and b.dname=bb.dname
group by a.deptno )
from emp aa,dept bb
where aa.deptno(+)=bb.deptno and aa.job='CLERK';
7.列出最低薪金大于1500的各种工作及从事此工作的全部雇员人数
select a.job,min(sal),count(ename) from emp a,dept b where a.deptno=b.deptno having min(sal)>1500group by a.job;
8.列出在部门SALES(销售部)工作的员工的姓名,假定不知道销售部的部门编号。

select ename from emp a,dept b where a.deptno=b.deptno and dname='SALES';
9.列出薪金高于公司平均薪金的所有员工,所在部门,上级领导,公司的等级工资select a.ename,dname,aa.ename "Leader" ,grade
from emp a,dept b,emp aa,salgrade s
where a.deptno=b.deptno and a.mgr=aa.empno and
a.sal>(select avg(sal) from emp)
and a.sal between losal and hisal;
10.列出与SCOTT从事相同工作的所有员工的编号,姓名,职位及其部门名称
select empno,ename,job,dname from emp a,dept b where a.deptno=b.deptno and job=(select job from emp where ename='SCOTT');
11.列出薪金等于部门30中员工的薪金的所有员工的姓名和薪金。

select ename,sal from emp where sal=any(select sal from emp where deptno=30);
12.列出薪金高于在部门30工作的所有员工的薪金的员工姓名、薪金和部门名称
select ename,sal,dname from emp a,dept b where a.deptno=b.deptno and sal>all(select sal from emp where deptno=30);
13.列出在每个部门工作的员工数量、平均工资和平均服务期限
select dname,count(ename),avg(sal),avg(sysdate - a.hiredate) from emp a,dept b where a.deptno(+)=b.deptno group by a.deptno,dname;
14.列出所有员工的姓名、部门名称和工资
select ename,dname,sal from emp a,dept b where a.deptno=b.deptno;
15.列出所有部门的详细信息和部门人数
select b.deptno,dname,loc,count(ename) from emp a,dept b where a.deptno(+)=b.deptno group by b.deptno,dname,loc;
16.列出各种工作的最低工资及从事此工作的雇员姓名
select b.ename,c "MIN SAL",a.job from (select job,min(sal) c from emp group by job) a,emp b where a.job=b.job and c=b.sal;
17.列出各个部门的MANAGER(经理)的最低薪金
select deptno,min(sal) from emp where job='MANAGER'group by deptno;
18.列出员工的年工资,按年薪从低到高排序
select ename,(sal+nvl(comm,0))*12 a from emp order by a;
19.查出某个员工的上级主管,并要求出这些主管中的薪水超过3000
select a.ename,b.ename,b.sal "boss sal" from emp a,emp b where a.mgr=b.empno and b.sal>=3000;。

相关文档
最新文档