susinlee 님의 블로그
113. 본문
[문제]
https://leetcode.com/problems/employees-whose-manager-left-the-company/description/
[풀이]
1. employee_id에 포함되지 않은 manager_id를 필터링하고
2. salary가 30000미만인 행들만 필터링해준다.
3. ~ 연산자를 사용해서 manager_id가 null임에도 필터링된 친구들을 dropna()로 날려버린다.
4. 정렬하고 조건에 맞게 열을 선택해서 반환한다.
Pandas
import pandas as pd
def find_employees(employees: pd.DataFrame) -> pd.DataFrame:
cond1 = ~employees.manager_id.isin(employees['employee_id'])
cond2 = employees.salary < 30000
return employees[cond1 & cond2].sort_values('employee_id').dropna()[['employee_id']]
SQL
SELECT employee_id
FROM Employees
WHERE
salary < 30000
AND manager_id NOT IN (SELECT employee_id FROM Employees)
ORDER BY employee_id;
'코드카타 > SQL, Pandas' 카테고리의 다른 글
115. Movie Rating (0) | 2025.01.30 |
---|---|
114. Exchange Seats (0) | 2025.01.30 |
111. Last Person to Fit in the Bus (0) | 2025.01.19 |
110. Product Price at a Given Date (0) | 2025.01.18 |
109. Consecutive Numbers (0) | 2025.01.17 |