-
leetcode - 1965. Employees With Missing InformationSQL 문제풀이 2022. 8. 7. 16:58
난이도 : Easy
Table: Employees
+-------------+---------+ | Column Name | Type | +-------------+---------+ | employee_id | int | | name | varchar | +-------------+---------+ employee_id is the primary key for this table. Each row of this table indicates the name of the employee whose ID is employee_id.Table: Salaries
+-------------+---------+ | Column Name | Type | +-------------+---------+ | employee_id | int | | salary | int | +-------------+---------+ employee_id is the primary key for this table. Each row of this table indicates the salary of the employee whose ID is employee_id.Write an SQL query 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, or
- The employee's salary is missing.
Return the result table ordered by employee_id in ascending order.
The query result format is in the following example.
Example 1:
Input: Employees table: +-------------+----------+ | employee_id | name | +-------------+----------+ | 2 | Crew | | 4 | Haven | | 5 | Kristian | +-------------+----------+ Salaries table: +-------------+--------+ | employee_id | salary | +-------------+--------+ | 5 | 76071 | | 1 | 22517 | | 4 | 63539 | +-------------+--------+ Output: +-------------+ | employee_id | +-------------+ | 1 | | 2 | +-------------+ Explanation: Employees 1, 2, 4, and 5 are working at this company. The name of employee 1 is missing. The salary of employee 2 is missing.SELECT e.employee_id FROM Employees e LEFT JOIN Salaries s ON e.employee_id = s.employee_id WHERE s.employee_id is null UNION SELECT s.employee_id FROM Salaries s LEFT JOIN Employees e ON e.employee_id = s.employee_id WHERE e.employee_id is null ORDER BY employee_idAccepted (79.10%)
'SQL 문제풀이' 카테고리의 다른 글
leetcode - 1355. Activity Participants (0) 2022.08.08 leetcode - 1978. Employees Whose Manager Left the Company (0) 2022.08.07 leetcode - 1939. Users That Actively Request Confirmation Messages (0) 2022.08.07 leetcode - 1341. Movie Rating (0) 2022.08.05 leetcode - 1321. Restaurant Growth (0) 2022.08.05