Leetcode
LeetCode 181. Employees Earning More Than Their Managers [MySql]
치킨먹고싶어요
2022. 6. 3. 17:39
https://leetcode.com/problems/employees-earning-more-than-their-managers/
Employees Earning More Than Their Managers - 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
코드 :
SELECT E1.Name AS Employee
FROM Employee E1, Employee E2
WHERE E1.managerId IS NOT NULL AND E2.id = E1.managerId AND E1.Salary > E2.Salary
|
cs |
풀이 :
1. E1.managerId IS NOT NULL을 사용하요 불필요한 연산을 줄여줍니다.
2. E2.id = E1.managerId를 이용하여 매니저와 직원을 연결시키고, 임금을 비교합니다.