我想通过首先将结果集限制为n个最高薪水,然后反转结果集并将其限制为1,来获得表中的第n个最高薪水。
我使用了此查询,这会导致错误:-
select *
from salaries
where emp_no=(select * from salaries order by salary desc limit 2) order by salary asc limit 1;
该错误表明子查询返回多行。
答案 0 :(得分:3)
答案 1 :(得分:2)
这是一种方法:
SELECT s.* FROM
(SELECT * FROM `salaries` ORDER BY salary DESC LIMIT 2) s
ORDER BY s.salary ASC LIMIT 1;
答案 2 :(得分:1)
select * from salaries
order by salary
desc limit 1 offset 4;