1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
-- @Title: 部门工资最高的员工 (Department Highest Salary)
-- @Author: 15816537946@163.com
-- @Date: 2021-03-03 15:33:14
-- @Runtime: 422 ms
-- @Memory: 0 B
# Write your MySQL query statement below

select D.Name as Department, E.Name as Employee, E.Salary as Salary
from 
Employee E,
Department D,
(select  DepartmentId, max(Salary) Salary
from Employee
Group By  DepartmentId) M

where E.DepartmentId =  D.Id
and  E.DepartmentId = M.DepartmentId
and E.Salary = M.Salary;