题目地址:https://leetcode.com/problems/department-highest-salary/
题解:根据部门id连接Employee表和Department表。然后对于每条记录,从另一个 Employee表中找出对应部门的最高薪水,并判断该员工的薪水是否等于部门最高薪水。
select d.Name as Department,e.Name as Employee,e.Salary
from Department as d,Employee as e
where d.Id=e.DepartmentId
and e.Salary=(select max(Salary)
from Employee as e2
where e2.DepartmentId=d.Id
);