题解 | #获取每个部门中当前员工薪水最高的相关信息#
获取每个部门中当前员工薪水最高的相关信息
https://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6
都是大神,我写了一个最基本的
select t1.dept_no,t1.emp_no,maxSalary
from
(select dept_no,d.emp_no,salary
from dept_emp d join salaries s
on d.emp_no = s.emp_no) t1 ### 二、找出所有人的薪资
join ### 俩表连接找出我们需要的字段就可以了
(select dept_no,max(salary) maxSalary
from dept_emp d join salaries s
on d.emp_no = s.emp_no
group by dept_no) t2 ### 先找出每个部门的最高薪资
on t1.dept_no = t2.dept_no
and t1.salary = t2.maxSalary
order by t1.dept_no
from
(select dept_no,d.emp_no,salary
from dept_emp d join salaries s
on d.emp_no = s.emp_no) t1 ### 二、找出所有人的薪资
join ### 俩表连接找出我们需要的字段就可以了
(select dept_no,max(salary) maxSalary
from dept_emp d join salaries s
on d.emp_no = s.emp_no
group by dept_no) t2 ### 先找出每个部门的最高薪资
on t1.dept_no = t2.dept_no
and t1.salary = t2.maxSalary
order by t1.dept_no