문제
Write a solution to report the IDs of all the employees with missing information. The information of an employee is missing if:
The employee's name is missing, orThe employee's salary is missing.
Return the result table ordered by employee_id in ascending order.
" 누락된 정보가 있는 모든 직원의 ID를 보고하는 솔루션을 작성합니다.
다음과 같은 경우에는 직원의 정보가 누락됩니다
1. 직원의 이름이 누락되었거나, 2. 직원의 급여가 누락되었습니다.
employee_id에서 주문한 결과표를 오름차순으로 반환합니다."
문제 풀이
1. salaryies 테이블에서의 employee_id가 포함되어 있지 않은 Employees 테이블의 employee_id를 구한다. 이때 서브쿼리를 활용하여 구해준다. (= 직원의 이름이 누락된 경우)
SELECT employee_id
FROM Employees
WHERE employee_id NOT IN (SELECT employee_id FROM Salaries
2. Employees 테이블에서의 employee_id가 포함되어 있지 않은 Salaries 테이블의 employee_id를 구한다. 이때 서브쿼리를 활용하여 구해준다. (= 직원의 급여가 누락된 경우)
SELECT employee_id
FROM Salaries
WHERE employee_id NOT IN (SELECT employee_id FROM Employees)
ORDER BY employee_id
3. 이 두가지를 UNION을 이용해서 합쳐준다.
SELECT employee_id
FROM Employees
WHERE employee_id NOT IN (SELECT employee_id FROM Salaries)
UNION
SELECT employee_id
FROM Salaries
WHERE employee_id NOT IN (SELECT employee_id FROM Employees)
ORDER BY employee_id
'취준 > 코팅 테스트' 카테고리의 다른 글
[LeetCode] 1084. Sales Analysis 3 (0) | 2024.04.10 |
---|---|
[LeetCode] - 608. Tree Node (0) | 2024.04.10 |
585. Investments in 2016 (0) | 2024.04.09 |
[LeetCode] - 1204. Last Person to Fit in the Bus (0) | 2024.04.06 |
[LeetCode] 1484. Group Sold Products By The Date (0) | 2024.04.06 |