문제
💡 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(=상사의 급여)인 데이터를 필터링해 해당 데이터의 직원이름을 출력해주었다
'SQL > 코딩테스트' 카테고리의 다른 글
[프로그래머스 / MySQL] 어린 동물 찾기 (0) | 2024.01.30 |
---|---|
[프로그래머스 / MySQL] 동물의 아이디와 이름 (0) | 2024.01.30 |
[leetcode / MySQL] 183. Customers Who Never Order (0) | 2024.01.29 |
[leetcode / MySQL] 1179. Reformat Department Table (4) | 2024.01.29 |
[프로그래머스 / MySQL] 즐겨찾기가 가장 많은 식당 정보 출력하기 (0) | 2024.01.29 |