如何在oracle的emp
表中找到前三名最高薪水?
答案 0 :(得分:13)
你可以试试。
SELECT * FROM
(
SELECT EMPLOYEE, LAST_NAME, SALARY,
RANK() OVER (ORDER BY SALARY DESC) EMPRANK
FROM emp
)
WHERE emprank <= 3;
即使有两名员工具有相同的最高工资
,这也会给出正确的输出答案 1 :(得分:11)
SELECT *FROM
(
SELECT *FROM emp
ORDER BY Salary desc
)
WHERE rownum <= 3
ORDER BY Salary ;
答案 2 :(得分:4)
以下内容应该这样做。
SELECT Name, Salary
FROM
(
SELECT Name, Salary
FROM emp
ORDER BY Salary desc
)
WHERE rownum <= 3
ORDER BY Salary ;
答案 3 :(得分:4)
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);
不使用TOP,ROWID,rank等。也适用于最老的SQL
答案 4 :(得分:0)
您可以使用DBMS_STAT_FUNCS.Summary
:
SET SERVEROUTPUT ON;
DECLARE
s DBMS_STAT_FUNCS.SummaryType;
BEGIN
DBMS_STAT_FUNCS.SUMMARY('HR', 'EMPLOYEES', 'SALARY',3, s);
DBMS_OUTPUT.put_line('Top 3: ' || s.top_5_values(1) || '-'
|| s.top_5_values(2) || '-' || s.top_5_values(3));
END;
/
输出:
Top 3: 24000-17000-17000
答案 5 :(得分:0)
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
答案 6 :(得分:0)
SELECT * FROM
(
SELECT EMPLOYEE, LAST_NAME, SALARY,
DENSE_RANK() OVER (ORDER BY SALARY DESC) EMPRANK
FROM emp
)
WHERE emprank <= 3;
答案 7 :(得分:-1)
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;
答案 8 :(得分:-1)
SELECT * FROM
(
SELECT ename, sal,
DENSE_RANK() OVER (ORDER BY SAL DESC) EMPRANK
FROM emp
)
emp1 WHERE emprank <=5
答案 9 :(得分:-1)
SELECT Name, Salary
FROM
(
SELECT Name, Salary
FROM emp
ORDER BY Salary desc
)
WHERE rownum <= 3
ORDER BY Salary ;
答案 10 :(得分:-1)
选择top(3)min(Name),TotalSalary,ROW_NUMBER()OVER(按TotalSalary desc排序)AS RowNumber 从TotalSalary到tbl_EmployeeProfile组
答案 11 :(得分:-1)
限制查询仅显示前三名最高薪员工。 :查询«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 ;
输出
LASTNAME SALARY
-------------------- ----------
Janey 5
Joey 4
Jacky 3
drop table employee;
答案 12 :(得分:-1)
SELECT salary,first_name||' '||last_name "Name of the employee"
FROM hr.employees
WHERE rownum <= 3
ORDER BY salary desc ;
答案 13 :(得分:-2)
select top 3 * from emp order by sal desc
答案 14 :(得分:-2)
SELECT DISTINCT(salary) FROM emp order by salary asc limit 0 ,3
以上查询通过 DISTINCT 给出三个最高薪水。
答案 15 :(得分:-2)
SELECT * FROM Employees
WHERE rownum <= 3
ORDER BY Salary ;
答案 16 :(得分:-2)
在sql server中找到前5名薪水的解决方案
从工资中的工资中选择最上面的(1)名称,工资(从工资光盘的工资单中选择不同的最高(3)工资)