我写了这个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 - “缺少右括号”
可能导致错误的原因是什么?
答案 0 :(得分:5)
Top-N查询通常以这种方式在Oracle中执行:
select * from (
select first_name, salary
from employees order by salary desc
) where rownum <= 10
这个可以获得十大薪水。
答案 1 :(得分:2)
我认为问题在于使用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
答案 2 :(得分:1)
尝试 -
SELECT first_name, salary
( select first_name, salary
from employees
order by salary Desc)
where rownum <= 10
答案 3 :(得分:0)
以下查询适用于Oracle。
select * from(select * from emp order by sal desc)其中rownum&lt; = 10;
答案 4 :(得分:-3)
试试这个=== SELECT first_name,salary FROM employees WHERE salary IN(SELECT salary FROM employees GROUP BY salary ORDER BY salary DESC LIMIT 10);