-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1965. Employees With Missing Information.sql
More file actions
53 lines (43 loc) · 1.38 KB
/
1965. Employees With Missing Information.sql
File metadata and controls
53 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Question 1965. Employees With Missing Information
Link: https://leetcode.com/problems/employees-with-missing-information/description/
Table: Employees
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| employee_id | int |
| name | varchar |
+-------------+---------+
employee_id is the column with unique values 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 column with unique values for this table.
Each row of this table indicates the salary of the employee whose ID is employee_id.
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, or
The employee's salary is missing.
Return the result table ordered by employee_id in ascending order.
*/
WITH all_employees AS (
SELECT employee_id
FROM Employees
UNION
SELECT employee_id
FROM Salaries
)
SELECT a.employee_id
FROM all_employees AS a
LEFT JOIN
Employees AS e
ON a.employee_id = e.employee_id
LEFT JOIN
Salaries AS s
ON a.employee_id = s.employee_id
WHERE e.name IS NULL OR s.salary IS NULL
ORDER BY a.employee_id ASC