https://leetcode-cn.com/problems/department-highest-salary/description/
找整张表中的最高薪水的员工就比较简单
子查询先找到最大薪水值
select Id,Name,Salary,DepartmentId from Employee
where Salary =
(select max(Salary) from Employee);
在上面的查询语句中加点限制条件就成了题目要求的答案
- 改名字
- Employee.DepartmentId = Department.Id 通过所属部门联系两张表
- 根据部门表的Id进行递增排序
select Department.Name as Department,Employee.Name as Employee,Salary
from Employee,Department
where Employee.DepartmentId = Department.Id
and Salary =
(select max(Salary) from Employee where Employee.DepartmentId = Department.Id)
order by Department.Id;