Skip to content

Commit 95553fb

Browse files
committed
Upload 125
1 parent 5959855 commit 95553fb

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ To make the daily tasks of creating a new file and updating the index easier, th
158158
| 122 | [Biggest Single Number](https://leetcode.com/problems/biggest-single-number/description/) | [Solution](solutions/122_biggest_single_number.md) | LeetCode | Easy | |
159159
| 123 | [Customers Who Bought All Products](https://leetcode.com/problems/customers-who-bought-all-products/description/) | [Solution](solutions/123_customers_who_bought_all_products.md) | LeetCode | Medium | |
160160
| 124 | [The Number of Employees Which Report to Each Employee](https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee/description/) | [Solution](solutions/124_the_number_of_employees_which_report_to_each_employee.md) | LeetCode | Easy | |
161+
| 125 | [Primary Department for Each Employee](https://leetcode.com/problems/primary-department-for-each-employee/description/) | [Solution](solutions/125_primary_department_for_each_employee.md) | LeetCode | Easy | `UNION` |
161162

162163
## Author(s)
163164

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SQL Everyday \#125
2+
3+
## Primary Department for Each Employee
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.
11+
12+
Return the result table in *any order*. [[Full Description](https://leetcode.com/problems/primary-department-for-each-employee/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
SELECT
19+
employee_id
20+
,department_id
21+
FROM Employee
22+
GROUP BY employee_id
23+
HAVING COUNT(department_id) = 1
24+
UNION
25+
SELECT
26+
employee_id
27+
,department_id
28+
FROM Employee
29+
WHERE primary_flag = 'Y'
30+
;
31+
```
32+
33+
## Site Solution
34+
35+
```sql
36+
-- LeetCode Solution
37+
-- Site solution essentially the same.
38+
```
39+
40+
## Notes
41+
42+
TODO
43+
44+
Go to [Table of Contents](/README.md#contents)\
45+
Go to [Overview](/README.md)

0 commit comments

Comments
 (0)