加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle面试题整理二(10级学员 乔宇整理)

发布时间:2020-12-12 14:37:11 所属栏目:百科 来源:网络整理
导读:Oracle面试题整理二(10级学员 乔宇整理) 1.查询工资最高的3 名员工信息 select * from (select * from emp order by sal desc) where rownum = 3; 分析我们先按照这个表中的工资降序排列, 然后使用伪列也就是这个rownum来取前三个 2. 按工资进行排名,排名

Oracle面试题整理二(10级学员 乔宇整理)

1.查询工资最高的3 名员工信息

select * from (select * from emp order by sal desc) where rownum <= 3;

分析我们先按照这个表中的工资降序排列,然后使用伪列也就是这个rownum来取前三个

2. 按工资进行排名,排名从1 开始,工资相同排名相同(如果两人并列第1 则没有第2 名,从第

三名继续排)

select rank() over(order by sal) from emp;

分析,其中用到一个rank() over的函数,自己在网上查一下就知道了,很简单的!

3. 求入职日期相同的(年月日相同)的员工

select * from emp e where (select count(*) from emp where e.hiredate=hiredate)>1;

4. 查询每个部门的最高工资

select deptno,max(sal) maxsal from emp group by deptno order by deptno;

分析这个没有什么要说的了,只要会分组就会了

5. 查询每个部门,每种职位的最高工资

分析这个和18一样的了

6. 查询每个员工的信息及工资级别(用到表Salgrade)

select * from salgrade;

select e.*,sg.grade from emp e,salgrade sg where sal between losal and hisal;

这个题目就是考察你的基础呢?呵呵很简单的

7. 查询工资最高的第6-10 名员工

select * from (

(select * from emp order by sal desc) e

where rownum <=10)

where rn > 5;

这个题目很有意思的啊,好好的分析一下

我们首先查询里面的 select * from emp order by sal desc就是按照降序查询,然后查出来伪列小于10的所有记录,然后我们在查询一次再找出记录大于五的,我们就知道了.

8. 查询各部门工资最高的员工信息

select * from emp e where e.sal = (select max(sal) from emp where (deptno = e.deptno));

首先查出来每个部分工资最高的然后根据序号对应得出各个部门的工资最高的员工信息

9.查询每个部门工资最高的前2 名员工

select rank() over (partition by deptno order by sal desc) rank,e.* from emp e

) where rank < 3;

这里解释一下,我们先用rank() over这个函数按照部门分组其中的工资降序,然后找到每个部门前两个就是了

10.查询出有3 个以上下属的员工信息

select * from emp e where

(select count(*) from emp where e.empno = mgr) > 2;

11. 查询所有大于本部门平均工资的员工信息()

select * from emp e where sal >

(select avg(sal) from emp where (deptno = e.deptno))

order by deptno;

12. 查询平均工资最高的部门信息

select d.*,avgsal from dept d,(select avg(sal) avgsal,deptno from emp group by deptno) se

where avgsal = (select max(avg(sal)) from emp group by deptno) and d.deptno = se.deptno;

分析:

步骤1:求每个部门的平均工资:

select avg(sal) avgsal,deptno from emp group by deptno;

步骤2:求最高的平均工资:

select max(avg(sal)) from emp group by deptno;

步骤3:求平均工资最高的部门信息,连接步骤1 产生的临时表与真实表dept:

select d.*,160)">where avgsal = (select max(avg(sal)) from emp group by deptno) and d.deptno = se.deptno;

13.查询大于各部门总工资的平均值的部门信息

where sumsal >(select avg(sum(sal)) from emp group by deptno) and se.deptno = d.deptno;

分析:

步骤1:求每个部门总工资

select sum(sal) sumsal,160)">步骤2:求每总工资平均值

select avg(sum(sal)) from emp group by deptno;

步骤3:求大于总工资平均值的部门信息,连接步骤1 产生的临时表与真实表dept:

where sumsal >(select avg(sum(sal)) from emp group by deptno) and se.deptno = d.deptno;

14. 查询大于各部门总工资的平均值的部门下的员工信息(考察知识点:子查询,组函数,连接

查询)

where sumsal >(select avg(sum(sal)) from emp group by deptno) and se.deptno = e.deptno;

这个题目呢,我们分析的时候是这样的,我们查找出来每个部门的总工资的平均工资,然后再查找出来每个部门的总工资,比较一下,然后根据部门号相等,就能算出来了

15. 查询没有员工的部门信息

select d.* from dept d left join emp e on (e.deptno = d.deptno) where empno is null;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读