题解 | #获取每个部门中当前员工薪水最高的相关信息#
获取每个部门中当前员工薪水最高的相关信息
http://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
先找出每个部门当前最高工资作为表1, 然后找出当前部门,员工,工资作为表2, 最后合并, 读取部门,员工,最高工资, 并按部门排序。
select a.dept_no, b.emp_no, a.salary from (select d.dept_no, max(s.salary) as salary from dept_emp d join salaries s on d.emp_no=s.emp_no where d.to_date='9999-01-01' and s.to_date='9999-01-01' group by d.dept_no) a inner join (select d.emp_no, s.salary, d.dept_no from dept_emp d join salaries s on d.emp_no = s.emp_no and d.to_date='9999-01-01' and s.to_date='9999-01-01') b on a.dept_no = b.dept_no and a.salary = b.salary order by a.dept_no;