题解 | #获取每个部门中当前员工薪水最高的相关信息#
获取每个部门中当前员工薪水最高的相关信息
http://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
#利用窗口函数,迎刃而解。窗口函数需要再熟悉熟悉!!!
SELECT dept_no, emp_no, salary
FROM (
SELECT d.dept_no, d.emp_no, s.salary, ROW_NUMBER()OVER(PARTITION BY d.dept_no ORDER BY s.salary DESC) rn
FROM dept_emp d
INNER JOIN salaries s
ON d.emp_no = s.emp_no
WHERE d.to_date = '9999-01-01'
) t
WHERE rn = 1;