



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、- - ( 1) 查询20 号部门的所有员工信息。select * from emp e where e.deptno=20;- -(2) 查询奖金(COMM高于工资(SAL.)的员工信息。select * from emp where comm>sal;- - ( 3)查询奖金高于工资的20%的员工信息。select * from emp where comm>sal*0.2;- -(4) 查询10号部门中工种为 MANAGER 20号部门中工种为 CLERK勺员工的信息。 select * from emp ewhere (e.deptno=10 and e.job='
2、MANAGER')or (e.deptno=20 and e.job='CLERK')- -(5) 查询所有工种不是 MANAGER CLERK- - 且工资大于或等于2000 的员工的详细信息。select * from empwhere job not in('MANAGER','CLERK') and sal>=2000;- - ( 6)查询有奖金的员工的不同工种。select * from emp where comm is not null;- - (7)查询所有员工工资和奖金的和。select (e.sal+nvl(m,
3、0) from emp e;- - (8)查询没有奖金或奖金低于100 的员工信息。select * from emp where comm is null or comm<100;- - (9)查询员工工龄大于或等于10 年的员工信息。select * from emp where (sysdate-hiredate)/365>=10;- - ( 10) 查 询员工信息,要求以首字母大写的方式显示所有员工的姓名。select initcap(ename) from emp;select upper(substr(ename,1,1)|lower(substr(ename,2) f
4、rom emp;- - ( 11) 显 示所有员工的姓名、入职的年份和月份,按入职日期所在的月份排序,- - 若月份相同则按入职的年份排序。select ename,to_char(hiredate,'yyyy') year,to_char(hiredate,'MM') month from emporder by month,year;- - ( 12) 查 询在 2 月份入职的所有员工信息。select * from emp where to_char(hiredate,'MM')='02'* 年 * 月 * 日”的形式表示。
5、- - ( 13) 查 询所有员工入职以来的工作期限,用“select e.ename,floor(sysdate-e.hiredate)/365)|'年|floor(mod(sysdate-e.hiredate),365)/30)|'月 '|floor(mod(mod(sysdate-e.hiredate),365),30)|'日from emp e;- - ( 14) 查 询从事同一种工作但不属于同一部门的员工信息。 select a.ename,a.job,a.deptno,b.ename,b.job,b.deptno from emp a,emp bwh
6、ere a.job=b.job and a.deptno<>b.deptno;- - ( 15) 查 询各个部门的详细信息以及部门人数、部门平均工资。select d.deptno,count(e.empno),avg(e.sal),d.dname,d.locfrom emp e ,dept dwhere e.deptno=d.deptnogroup by d.deptno,d.dname,d.loc- - ( 16) 查 询 10 号部门员工以及领导的信息。select * from emp where empno in(select mgr from emp where dep
7、tno=10) or deptno=10;- - ( 17) 查 询工资为某个部门平均工资的员工信息。select * from empwhere sal in(select avg(sal) from emp group by deptno);- - ( 18) 查 询工资高于本部门平均工资的员工的信息。select * from emp e1where sal >(select avg(sal) from emp e2 where e2.deptno=e1.deptno);- - ( 19) 查 询工资高于本部门平均工资的员工的信息及其部门的平均工资。select e.*,a.avg
8、salfrom emp e,(select deptno,avg(sal) as avgsal from emp group by deptno) a where a.deptno=e.deptno and e.sal>a.avgsal;- - ( 20) 统 计各个工种的人数与平均工资。select count(*),e.job,avg(e.sal) from emp egroup by e.job- - ( 21) 统 计每个部门中各个工种的人数与平均工资。select deptno,job,count(empno),avg(sal) from emp egroup by e.dep
9、tno,e.job- - ( 22) 查 询所有员工工资都大于1000 的部门的信息。select * from dept where deptno in(select deptno from empwhere deptno not in(select distinct deptno from emp where sal<1000);- - ( 23) 查 询所有员工工资都大于1000 的部门的信息及其员工信息。select * from emp e join dept d on d.deptnoin (select deptno from empwhere deptno not in(
10、select distinct deptno from emp where sal<1000)and d.deptno=e.deptno;- - ( 24) 查 询所有员工工资都在9003000 之间的部门的信息。select * from deptwhere deptno not in(select deptno from empwhere sal not between 900 and 3000);- - ( 25) 查 询所有工资都在9003000 之间的员工所在部门的员工信息。select * from emp awhere a.deptno in(select distinct
11、 e.deptno from emp ewhere e.sal between 900 and 3000);- - ( 26) 查 询每个员工的领导所在部门的信息。select d.* from dept dwhere d.deptno in(select distinct e2.deptno from emp e1,emp e2where e1.empno=e2.mgr);- - ( 27) 查 询人数最多的部门信息。select * from deptwhere deptno in(select deptno from (select count(*) count,deptno from
12、emp group by deptno) where count in(select max(count)from (select count(*) count ,deptno from emp group by deptno);- - ( 28) 查 询 30 号部门中工资排序前3 名的员工信息。select * from(select sal from emp where deptno=30 order by sal desc) ewhere rownum<4- -(29)查询'JONES'员工及所有其直接、间接下属员工的信息。select e.* from emp
13、estart with ename='JONES'connect by prior empno=mgr;- -(30)查询SCOTIM工及其直接、间接上级员工的信息。select e.* from emp estart with ename='SCOTT'connect by prior mgr=empno;- - ( 31) 以 树状结构查询所有员工与领导之间的层次关系。select substr(sys_connect_by_path(ename,'->'),3),levelfrom empstart with mgr is nullc
14、onnect by prior empno=mgr;- -(32)向emp表中插入一条记录,员工号为1357,员工名字为 oracle ,- - 工资为 2050 元,部门号为20,入职日期为2002 年 5 月 10 日。- - ( 33)将各部门员工的工资修改为该员工所在部门平均工资加1000。update emp e set sal=1000+(select avg(sal) from emp where deptno=e.deptno);- -(34)查询工作等级为2级,1985年以后入职的工作地点为DALLAS勺员工编号、- - 姓名和工资。select e.ename,e.empn
15、o,e.sal from emp e,salgrade s,dept dwhere (e.sal between s.losal and s.hisal)and (s.grade=2)and to_char(e.hiredate,'yyyy')>1985and e.deptno=d.deptnoand d.loc='DALLAS'- -35. 部门平均薪水最高的部门编号select * from(select avg(sal) avgsal,deptnofrom emp group by deptno order by avgsal desc)where
16、rownum=1;select deptno,avg(sal) from emp group by deptno having avg(sal)=(select max(avg(sal) avgsalfrom emp group by deptno)-36, 部门平均薪水最高的部门名称select d.* from dept d where deptno in(select deptno from emp group by deptno having avg(sal)=( select max(avg(sal) avgsalfrom emp group by deptno)-37. 平均薪水最
17、低的部门的部门名称select d.* from dept d where deptno in(select deptno from emp group by deptno having avg(sal)=(select min(avg(sal) avgsalfrom emp group by deptno)- -38. 平均薪水等级最低的部门的部门名称select d.dname from dept dwhere d.deptno in(select a.deptno from(select e.deptno from emp e,salgrade swhere (e.sal between
18、 s.losal and s.hisal)group by e.deptno order by avg(s.grade) awhere rownum=1);- -39. 部门经理人中,薪水最低的部门名称select dname from dept where deptno=(select deptno from(select deptno from emp where job='MANAGER' group by deptnoorder by min(sal) where rownum=1)- -40. 比普通员工的最高薪水还要高的经理人名称select ename from e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论