184. 部门工资最高的员工
目录
1. 题目
2. 解题
# Write your MySQL query statement below
select
Department.Name as Department,
Employee.Name Employee,
Salary
from
Employee,
Department
where
Employee.DepartmentId=Department.Id
and (Employee.DepartmentId, Salary) in (
select Department.Id, max(Salary)
from Employee,Department
where DepartmentId=Department.Id
group by Department.Id
);
分步骤分析:
1. 找出各个部门最大的薪资(部门id + 薪资水平)
2. 关联Employee表和Department表,用in和步骤1中的部门id和薪资做匹配