方法1)dense_rank()over() 求工资排名第二的记录
SELECT a.emp_no, a.salary -- 再套一层查询 FROM( SELECT emp_no, salary, dense_rank()over(ORDER BY salary DESC)rank_num FROM salaries WHERE to_date = '9999-01-01')a WHERE a.rank_num = 2;
- 注意外面要再套一层查询
方法2)不那么严谨但是能过的ORDER BY + LIMIT + OFFSET
SELECT emp_no, salary FROM salaries WHERE to_date = '9999-01-01' ORDER BY salary DESC LIMIT 1 OFFSET 1;
- 这种情况下如果同一工资有多条记录不适用