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:59
 SELECT * FROM 
     (
      SELECT EMPLOYEE, LAST_NAME, SALARY,
      DENSE_RANK() OVER (ORDER BY SALARY DESC) EMPRANK
      FROM emp
     )
    WHERE emprank <= 3;
查看更多
Animai°情兽
3楼-- · 2020-02-24 05:00
SELECT  Name, Salary
FROM 
    (
    SELECT  Name, Salary
    FROM         emp 
    ORDER BY Salary desc
    )
WHERE rownum <= 3
ORDER BY Salary ;
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-02-24 05:01

Limit The Query To Display Only The Top 3 Highest Paid Employees. : Query « Oracle PL / SQL

create table employee(
         emp_no                 integer         primary key
        ,lastname               varchar2(20)    not null
        ,salary                 number(3)
);

insert into employee(emp_no,lastname,salary)
              values(1,'Tomy',2);

insert into employee(emp_no,lastname,salary)
              values(2,'Jacky',3);

insert into employee(emp_no,lastname,salary)
              values(3,'Joey',4);

insert into employee(emp_no,lastname,salary)
              values(4,'Janey',5);


select lastname,  salary
from (SELECT lastname, salary FROM employee ORDER BY salary DESC)
where rownum <= 3 ;

OUTPUT

LASTNAME                 SALARY

-------------------- ----------
Janey                         5

Joey                          4

Jacky                         3

drop table employee;
查看更多
Explosion°爆炸
5楼-- · 2020-02-24 05:02
SELECT * FROM Employees
WHERE rownum <= 3
ORDER BY Salary ;
查看更多
【Aperson】
6楼-- · 2020-02-24 05:03

select top(3) min(Name),TotalSalary,ROW_NUMBER() OVER (Order by TotalSalary desc) AS RowNumber FROM tbl_EmployeeProfile group by TotalSalary

查看更多
Lonely孤独者°
7楼-- · 2020-02-24 05:04
SELECT a.ename, b.sal
    FROM emp a, emp b
    WHERE a.empno = b.empno
          AND
          3 > (SELECT count(*) FROM emp b
                   WHERE a.sal = b.sal);

Without using TOP, ROWID, rank etc. Works with oldest sql also

查看更多
登录 后发表回答