思考

  1. 查找当前的最高薪水
    select max(salary) from salaries
  2. 查找当前第二高的薪水
    select max(salary) from salaries
    where salary < (
         select max(salary) from salaries)
  3. 查找 薪水=第2步中所查找出来的薪水 的员工emp_no等信息

答案

select e.emp_no, salary, last_name, first_name
from employees e, salaries s
where e.emp_no = s.emp_no
and salary = (
    select max(salary) from salaries
    where salary < (
        select max(salary) from salaries)
);

注意

刚开始写的是 select emp_no, xxx 自测报错提示如下:

SQL_ERROR_INFO: "Column 'emp_no' in field list is ambiguous"

主要是因为emp_no在employees和salaries两个表中都有