当前位置:   article > 正文

oracle数据库中关于部门工资前三高的查询(重点学习思路)_oracle查询工资最高的三个人

oracle查询工资最高的三个人

oracle数据库中我使用的是Scott登录进行的部门工资前三高的查询,可能有很多方法,但是我没想到,于是请教大神提供了一种方法:

查询每个部门的工资最高前三名

1,方法一

select deptno, ename, sal      
from emp e1     
where      
   (  
    select count(1)     
    from emp e2     
    where e2.deptno=e1.deptno and e2.sal>=e1.sal  
   ) <=3 /*这里的数值表示你想取前几名*/  
order by deptno, sal desc;

2,方法二
-- row_number 生成的行连续号,没有重复的
select t.*
from (select row_number() over(PARTITION by deptno order by sal desc) rn,e.* from emp e) t
where t.rn <= 3;

3,方法三
---dence_rank在并列关系时,相同等级不会跳过。rank则跳过

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

where t.rn <= 3;

4,方法四
select t.*
from (select dense_rank() over(PARTITION by deptno order by sal desc) rn,e.* from emp e) t
where t.rn <= 3;


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/615176
推荐阅读
相关标签
  

闽ICP备14008679号