문제
Write a solution to find employees who have the highest salary in each of the departments.
Return the result table in any order.
The result format is in the following example.
쿼리
SELECT
B.NAME AS DEPARTMENT,
A.NAME AS EMPLOYEE,
A.SALARY AS SALARY
FROM
EMPLOYEE A
LEFT JOIN
DEPARTMENT B
ON A.DEPARTMENTID = B.ID
WHERE
(A.DEPARTMENTID, A.SALARY) IN (
SELECT
DEPARTMENTID,
MAX(SALARY) AS SAL
FROM
EMPLOYEE
GROUP BY
DEPARTMENTID
);
PARTITION BY랑 RANK() 함수 사용해서 푸는 풀이법이 더 빠른 것 같긴 하던데 아직은 연습이 조금 더 필요할 것 같다.
문제 출처
'Study > SQL' 카테고리의 다른 글
| [LeetCode] 196. Delete Duplicate Emails (0) | 2025.12.01 |
|---|---|
| [LeetCode] 185. Department Top Three Salaries (0) | 2025.11.27 |
| [LeetCode] 183. Customers Who Never Order (0) | 2025.11.25 |
| [LeetCode] 182. Duplicate Emails (0) | 2025.11.25 |
| [LeetCode] 180. Consecutive Numbers (0) | 2025.11.19 |