我编写了这个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-“缺少右括号”
是什么导致了这个错误?
gj3fmq9x1#
在Oracle中,Top-N查询通常是这样执行的:
select * from ( select first_name, salary from employees order by salary desc ) where rownum <= 10
这一条能让你拿到前10名的薪水。
pinkon5k2#
我认为问题出在top的使用上,它是SQL Server而不是Oracle。
top
改用rank来按体面的顺序拿到薪水,并拿到前10个:
rank
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
watbbzwu3#
试着-
SELECT first_name, salary ( select first_name, salary from employees order by salary Desc) where rownum <= 10
ruyhziif4#
The below Query works in Oracle.
select * from (select * from emp order by sal desc) where rownum<=10;
kiayqfof5#
这会行得通的
select emp_id, salary from orders order by salary desc limit 10;
j2cgzkjk6#
Try This=SELECT FIRST_NAME,Salary from Employees where Salary IN(按薪资顺序按薪资级别限制从员工组中选择薪资10);
6条答案
按热度按时间gj3fmq9x1#
在Oracle中,Top-N查询通常是这样执行的:
这一条能让你拿到前10名的薪水。
pinkon5k2#
我认为问题出在
top
的使用上,它是SQL Server而不是Oracle。改用
rank
来按体面的顺序拿到薪水,并拿到前10个:watbbzwu3#
试着-
ruyhziif4#
The below Query works in Oracle.
select * from (select * from emp order by sal desc) where rownum<=10;
kiayqfof5#
这会行得通的
j2cgzkjk6#
Try This=SELECT FIRST_NAME,Salary from Employees where Salary IN(按薪资顺序按薪资级别限制从员工组中选择薪资10);