题解 | 在子查询中使用窗口函数,计算每组工资排序rk
获取每个部门中当前员工薪水最高的相关信息
https://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
SELECT dept_no, emp_no, salary AS maxSalary FROM( SELECT de.emp_no, de.dept_no, s.salary, RANK() OVER(PARTITION BY dept_no ORDER BY salary DESC) AS rk FROM dept_emp de JOIN salaries s USING(emp_no) ) t1 WHERE rk=1 ORDER BY dept_no