逻辑是通过where限制salary<max(salary)同时salary不能小于除了max(salary)以外其他salary的值。所以这里我先用子查询获取了max(salary),在where中用emp_no连接salaries和employees两张表,然后限制salary小于max(salary)并且大于等于所有小于max(salary)的值,这里我通过另一个选出小于max(salary)的最大值的子查询实现。
select e.emp_no, s.salary, e.last_name, e.first_name
from employees as e, salaries as s,
(select max(salary) as maxs from salaries) as temp
where s.emp_no = e.emp_no and s.salary < temp.maxs and
s.salary >= (select max(salary) from salaries
where salary < temp.maxs)