SQL/SQL 문제
[Leetcode] 184. Department Highest Salary
Lim Seung Hyun
2022. 3. 25. 16:09
문제 출처
Department Highest Salary - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
나의 풀이(MySQL)
select dep.name as Department, emp.name as Employee, emp.salary as Salary
from
-- part별 최대 급여를 받는 사람을 조회
(select e.name, e.salary, e.departmentId
from
-- part별 최대 급여 게산
(select departmentId, max(salary) as max_salary
from Employee as e
group by departmentId) as ds
join Employee as e on ds.departmentId = e.departmentId
where e.salary = ds.max_salary) as emp
join Department as dep on emp.departmentId = dep.id
728x90