题解 | #获取每个部门中当前员工薪水最高的相关信息#
获取每个部门中当前员工薪水最高的相关信息
http://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
当多人同时拥有最高薪水时直接用max(s.salary)无法查出
因此,用dense_rank分组排序,最高薪水相同的并列第一, t_rank=1
select dept_no,emp_no,salary from
(select d.dept_no,s.emp_no,salary,
dense_rank() over (partition by dept_no order by salary desc) as t_rank
from dept_emp as d
inner join salaries as s
on d.emp_no=s.emp_no
where d.to_date='9999-01-01' and s.to_date='9999-01-01') as a
where t_rank=1;
js