题解 | #获取每个部门中当前员工薪水最高的相关信息#
获取每个部门中当前员工薪水最高的相关信息
https://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
-- 直接暴力开窗
select rk.dept_no, rk.emp_no, salary as maxSalary
from (
select e.dept_no, e.emp_no, salary, row_number()over(partition by dept_no order by salary desc) as posn
from dept_emp e
join salaries s using(emp_no)
) as rk
where rk.posn = 1
from (
select e.dept_no, e.emp_no, salary, row_number()over(partition by dept_no order by salary desc) as posn
from dept_emp e
join salaries s using(emp_no)
) as rk
where rk.posn = 1