1. 程式人生 > >LeetCode #184 部門工資最高的員工

LeetCode #184 部門工資最高的員工

找整張表中的最高薪水的員工就比較簡單

子查詢先找到最大薪水值

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;