时间:2021-07-01 10:21:17 帮助过:2人阅读
SELECT e.emp_no, MAX(s.salary) AS salary, e.last_name, e.first_name
FROM employees AS e INNER JOIN salaries AS s
ON e.emp_no = s.emp_no
WHERE s.to_date =
‘9999-01-01‘
AND s.salary NOT IN (SELECT MAX(salary) FROM salaries WHERE to_date =
‘9999-01-01‘
)
方法二:
利用max选出最大,用where 限定小于最大值的,然后再取最大的那个
select a.emp_no,max(b.salary),a.last_name,a.first_name
from employees a inner join salaries b
on a.emp_no=b.emp_no
where b.salary<(select max(salary) from salaries)
and b.to_date = ‘9999-01-01‘
sql不用order by查找第二的思路
标签:使用 join log color date rom tab 最大值 key