문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
Table: Employees
| Column Name | Type |
|---|---|
| employee_id | int |
| name | varchar |
| manager_id | int |
| salary | int |
employee_id는 이 테이블의 기본 키이다.
테이블은 직원, 급여, 매니저의 ID 정보를 포함한다. 어떤 직원은 매니저를 가지고 있지 않다.
급여가 $30000 미만이고 매니저가 회사를 그만둔 직원의 ID를 찾아라. 매니저가 회사를 그만두면 Employees 테이블에서 매니저의 정보는 삭제되지만, 직원들의 정보에는 여전히 매니저의 ID가 manager_id에 있다.
Input:
Employees table:
| employee_id | name | manager_id | salary |
|---|---|---|---|
| 3 | Mila | 9 | 60301 |
| 12 | Antonella | null | 31000 |
| 13 | Emery | null | 67084 |
| 1 | Kalel | 11 | 21241 |
| 9 | Mikaela | null | 50937 |
| 11 | Joziah | 6 | 28485 |
Output:
| employee_id |
|---|
| 11 |
-- Write your PostgreSQL query statement below
select A.employee_id
from Employees A
left outer join Employees B on A.manager_id = B.employee_id
where A.salary < 30000 and A.manager_id is not null and B.employee_id is null
order by A.employee_id