How to find top three highest salary in emp table

2020-02-24 04:09发布

How to find top three highest salary in emp table in oracle?

17条回答
迷人小祖宗
2楼-- · 2020-02-24 04:49
SELECT  *FROM 
    (
    SELECT *FROM emp 
    ORDER BY Salary desc
    )
WHERE rownum <= 3
ORDER BY Salary ;
查看更多
女痞
3楼-- · 2020-02-24 04:55
SELECT salary,first_name||' '||last_name "Name of the employee" 
FROM hr.employees 
WHERE rownum <= 3 
ORDER BY salary desc ;
查看更多
我想做一个坏孩纸
4楼-- · 2020-02-24 04:55
    select empno,salary from emp e
     where 3 > ( Select count(salary) from emp
      where e.salary < salary )


Another way :

    select * from
    (
    select empno,salary,
    Rank() over(order by salary desc) as rank from emp )
    where Rank <= 3;

Another Way :

    select * from
    (
    select empno,salary from emp
    order by salary desc
    )
    where rownum <= 3;
查看更多
小情绪 Triste *
5楼-- · 2020-02-24 04:56

solution for to find top 5 salary in sq l server

select top(1) name, salary from salary where salary in(select distinct top(3) salary from salary order by salary disc)

查看更多
够拽才男人
6楼-- · 2020-02-24 04:58

You can try.

   SELECT * FROM 
     (
      SELECT EMPLOYEE, LAST_NAME, SALARY,
      RANK() OVER (ORDER BY SALARY DESC) EMPRANK
      FROM emp
     )
    WHERE emprank <= 3;

This will give correct output even if there are two employees with same maximun salary

查看更多
女痞
7楼-- · 2020-02-24 04:58
Select ename, job, sal from emp
    where sal >=(select max(sal) from emp
    where sal < (select max(sal) from emp
    where sal < (select max(sal) from emp)))
    order by sal;

ENAME      JOB              SAL
---------- --------- ----------
KING       PRESIDENT       5000
FORD       ANALYST         3000
SCOTT      ANALYST         3000
查看更多
登录 后发表回答