从Employees表中选择前10名薪资

uqjltbpv  于 2022-09-18  发布在  Java
关注(0)|答案(6)|浏览(130)

我编写了这个SQL查询:

select first_name, salary 
from employees 
where salary in( select distinct top(10) salary from employees order by salary  disc );

当我运行它时,我得到了这样的错误:

SQL错误:ORA-00907:缺少右括号00907。00000-“缺少右括号”

是什么导致了这个错误?

gj3fmq9x

gj3fmq9x1#

在Oracle中,Top-N查询通常是这样执行的:

select * from (
select first_name, salary 
from employees order by salary desc
) where rownum <= 10

这一条能让你拿到前10名的薪水。

pinkon5k

pinkon5k2#

我认为问题出在top的使用上,它是SQL Server而不是Oracle。

改用rank来按体面的顺序拿到薪水,并拿到前10个:

select v.first_name, v.salary 
from ( select first_name, salary, rank() over (order by salary desc) r from employees) v
where v.r <= 10
watbbzwu

watbbzwu3#

试着-

SELECT first_name, salary 
(  select first_name, salary 
   from employees 
   order by salary Desc)
where rownum <= 10
ruyhziif

ruyhziif4#

The below Query works in Oracle.

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

kiayqfof

kiayqfof5#

这会行得通的

select emp_id, salary from orders
order by salary desc limit 10;
j2cgzkjk

j2cgzkjk6#

Try This=SELECT FIRST_NAME,Salary from Employees where Salary IN(按薪资顺序按薪资级别限制从员工组中选择薪资10);

相关问题