[LeetCode/SQL]
📌 184. Department Highest Salary
풀이
부서별 가장 높은 연봉을 가진 직원을 찾아서 출력하라.
방법 I
SELECT d.name AS Department
,e.name AS Employee
,e.salary AS Salary
FROM Department AS d,Employee AS e
WHERE e.departmentId=d.id AND (e.departmentId,salary) IN
(SELECT departmentId,MAX(salary)
FROM Employee
GROUP BY departmentId)
방법 II
SELECT d.name AS Department
,e.name AS Employee
,Salary
FROM (
SELECT *,MAX(salary) OVER (PARTITION BY DepartmentId) AS max_val
FROM Employee) AS e
JOIN Department AS d
ON e.DepartmentId=d.Id
WHERE salary=max_val