Skip to content

Commit bf102cc

Browse files
committed
Upload 160
1 parent ab6cb72 commit bf102cc

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ Because this project necessitated a framework to enable consistent daily practic
188188
| 157 | [Rearrange Products Table](https://leetcode.com/problems/rearrange-products-table/description/) | [Solution](solutions/157_rearrange_products_table.md) | LeetCode | Easy | |
189189
| 158 | [Calculate Special Bonus](https://leetcode.com/problems/calculate-special-bonus/description/) | [Solution](solutions/158_calculate_special_bonus.md) | LeetCode | Easy | |
190190
| 159 | [The Latest Login in 2020](https://leetcode.com/problems/the-latest-login-in-2020/description/) | [Solution](solutions/159_the_latest_login_in_2020.md) | LeetCode | Easy | |
191+
| 160 | [Employees With Missing Information](https://leetcode.com/problems/employees-with-missing-information/description/) | [Solution](solutions/160_employees_with_missing_information.md) | LeetCode | Easy | FULL JOIN |
191192
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
192193
<!--- cSpell:enable --->
193194

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# SQL Everyday \#160
2+
3+
## Employees With Missing Information
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Write a solution to report the IDs of all the employees with *missing information*. The information of an employee is missing if:
11+
12+
* The employee's *name* is missing, or
13+
* The employee's *salary* is missing.
14+
15+
Return the result table ordered by `employee_id` *in ascending order*. [[Full Description](https://leetcode.com/problems/employees-with-missing-information/description/)]
16+
17+
## Submitted Solution
18+
19+
```sql
20+
-- Submitted Solution
21+
SELECT
22+
COALESCE(e.employee_id, s.employee_id) AS employee_id
23+
FROM Employees AS e
24+
FULL JOIN Salaries AS s ON e.employee_id = s.employee_id
25+
WHERE e.name IS NULL
26+
OR s.salary IS NULL
27+
ORDER BY employee_id ASC
28+
;
29+
```
30+
31+
## Site Solution
32+
33+
```sql
34+
-- LeetCode Solution
35+
-- Solution #1: Simulate Full Join via Unioning a Left and Right Join
36+
SELECT
37+
T.employee_id
38+
FROM
39+
(
40+
SELECT
41+
*
42+
FROM
43+
Employees
44+
LEFT JOIN Salaries USING(employee_id)
45+
UNION
46+
SELECT
47+
*
48+
FROM
49+
Employees
50+
RIGHT JOIN Salaries USING(employee_id)
51+
) AS T
52+
WHERE
53+
T.salary IS NULL
54+
OR T.name IS NULL
55+
ORDER BY
56+
employee_id;
57+
58+
-- Solution #2: `UNION` with `WHERE ... NOT IN`
59+
SELECT
60+
employee_id
61+
FROM
62+
Employees
63+
WHERE
64+
employee_id NOT IN (
65+
SELECT
66+
employee_id
67+
FROM
68+
Salaries
69+
)
70+
UNION
71+
SELECT
72+
employee_id
73+
FROM
74+
Salaries
75+
WHERE
76+
employee_id NOT IN (
77+
SELECT
78+
employee_id
79+
FROM
80+
Employees
81+
)
82+
ORDER BY
83+
employee_id ASC
84+
```
85+
86+
## Notes
87+
88+
TBD
89+
90+
## NB
91+
92+
FULL JOIN
93+
94+
Go to [Index](../?tab=readme-ov-file#index)\
95+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)