융무의 기술블로그
article thumbnail

https://leetcode.com/problems/department-highest-salary/

 

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

Problem                                                                                                                      

Analysis                                                                                                                     

1. Employee의 DepartmentId 와 Department의 Id가 같은 곳을 JOIN한다.

2. 그중에 MAX함수를 사용하여 Salary가 높은 곳을 찾는다.

 

Solution                                                                                                                    

SELECT D.NAME AS Department,E.Name AS Employee, E.Salary   
FROM Employee AS E
JOIN Department AS D ON E.DepartmentId = D.Id 
    AND E.Salary = (
        SELECT MAX(Salary) 
        FROM Employee AS T
        WHERE T.DepartmentId = E.DepartmentId
    );
profile

융무의 기술블로그

@융무

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!