susinlee 님의 블로그
Replace Employee ID With The Unique Identifier 본문
[문제]
Write a solution to show the unique ID of each user, If a user does not have a unique ID replace just show null.
Return the result table in any order.
The result format is in the following example.
[풀이]
1. unique_id 가 존재하지 않으면 null을 표시해야하니까 employee 테이블 기준으로 LEFT 조인을 해야함
2. unique_id와 name을 조회
Pandas
import pandas as pd
def replace_employee_id(employees: pd.DataFrame, employee_uni: pd.DataFrame) -> pd.DataFrame:
# df = employees.merge(employee_uni, on='id', how='left')
df = pd.merge(employees, employee_uni, on='id', how='left')
return df[['unique_id', 'name']]
SQL
SELECT unique_id,
name
FROM Employees E
LEFT JOIN EmployeeUNI U
ON E.id = U.id
'코드카타 > SQL, Pandas' 카테고리의 다른 글
Product Sales Analysis 1 (0) | 2024.12.20 |
---|---|
대충 만든 자판 (0) | 2024.12.19 |
Invalid Tweets (0) | 2024.12.19 |
이빠진 데이터를 채워넣어보자 (재귀 테이블, 윈도우 함수) (0) | 2024.12.14 |
상품을 구매한 회원 비율 구하기 (1) | 2024.12.14 |