LeetCode - 184. Department Highest Salary (MySQL)

조민수·2024년 6월 7일
0

LeetCode

목록 보기
22/61

Medium, SQL - Couple로 Tuple 비교하기

RunTime : 740 ms


문제

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.


풀이

  • 쌍으로 비교할 땐 =가 아니라 IN을 써야한다.
    • = 썼다가 계속 틀렸음
SELECT D.name AS Department, E.name AS Employee, E.salary AS Salary
FROM Department AS D JOIN Employee AS E ON E.departmentId = D.id
WHERE (Salary, E.departmentId) IN
(
    SELECT MAX(salary), departmentId FROM Employee
    GROUP BY departmentId
)
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글