[LeetCode/SQL] 1978. Employees Whose Manager Left the Company

Sooyeon·2023년 12월 4일
0

문제풀이 

목록 보기
68/95
post-thumbnail

[LeetCode/SQL]


📌 1978. Employees Whose Manager Left the Company

문제

풀이

직원의 월급이 30000달러 이하이고 매니저가 회사를 떠난 
직원의 아이디를 출력하라. 

방법 I

  • WHERE 절 서브쿼리
SELECT employee_id
FROM Employees
WHERE manager_id NOT IN (SELECT employee_id
                         FROM Employees)
AND salary <30000
ORDER BY employee_id

방법 II

  • SELF JOIN
SELECT e1.employee_id
FROM Employees e1
LEFT JOIN Employees e2
ON e1.manager_id =e2.employee_id
WHERE e1.manager_id IS NOT NULL
AND e2.employee_id IS  NULL
AND e1.salary <30000
ORDER BY e1.employee_id

0개의 댓글