본문 바로가기
SQL/코딩테스트

[leetcode / MySQL] 181. Employees Earning More Than Their Managers

by Hi_heidi 2024. 1. 29.

문제

💡 Write a solution to find the employees who earn more than their managers. Return the result table in any order.

 

테이블 형태

 

풀이

SELECT E1.name AS Employee
FROM Employee AS E1
    JOIN Employee AS E2 ON E1.managerId=E2.id
WHERE E1.salary > E2.salary

 

해설

SELECT E1.name AS Employee
FROM Employee AS E1
    JOIN Employee AS E2 ON E1.managerId=E2.id
WHERE E1.salary > E2.salary
  • 상사보다 높은 급여를 받은 직원을 출력하는 문제다. managerId를 기준으로 SELF JOIN한 뒤 WHERE절에 E1 의 급여(=직원의 급여) > E2(=상사의 급여)인 데이터를 필터링해 해당 데이터의 직원이름을 출력해주었다