题解 | #获取每个部门中当前员工薪水最高的相关信息#
获取每个部门中当前员工薪水最高的相关信息
https://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
如果求多个员工的最高工资就用两个子查询,一个是保存每个部门的最高工资,另一个是保存当前人员部门,然后两个子查询设置条件内容。
条件是薪水相等,和部门相等
select s.dept_no,s.emp_no,m.salary as salary
from(
select d.dept_no,max(s.salary) salary
from salaries as s join dept_emp d
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
)m
,(
select d.dept_no,s.emp_no,s.salary
from salaries s join dept_emp d
on d.emp_no=s.emp_no
where d.to_date='9999-01-01' and s.to_date="9999-01-01"
) s
where s.dept_no=m.dept_no
and s.salary=m.salary
order by s.dept_no
深信服公司福利 878人发布