先找到最大薪水
select max(salary) from salaries where to_date = '9999-01-01'
然后将上面的结果作为一个条件,查找第二大!
select max(salary) from salaries where to_date = '9999-01-01' and salary < (select max(salary) from salaries where to_date = '9999-01-01')
最后联结两个表就可以得到想要的结果!
SELECT a.emp_no, b.salary,a.last_name,a.first_name from employees a inner join salaries b
on a.emp_no = b.emp_no
where to_date = '9999-01-01'
and b.salary =
(
select max(salary) from salaries where to_date = '9999-01-01'
and salary < (select max(salary) from salaries where to_date = '9999-01-01')
)