Skip to content

Commit 305b935

Browse files
committed
task: #570
1 parent 3aea820 commit 305b935

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Have a good contributing!
5757
2. [Medium](./leetcode/medium/)
5858
- [176. Second Highest Salary](./leetcode/medium/176.%20Second%20Highest%20Salary.sql)
5959
- [184. Department Highest Salary](./leetcode/medium/184.%20Department%20Highest%20Salary.sql)
60+
- [570. Managers with at Least 5 Direct Reports](./leetcode/medium/570.%20Managers%20with%20at%20Least%205%20Direct%20Reports.sql)
6061
- [602. Friend Requests II: Who Has the Most Friends](./leetcode/medium/602.%20Friend%20Requests%20II:%20Who%20Has%20the%20Most%20Friends.sql)
6162
- [1045. Customers Who Bought All Products](./leetcode/medium/1045.%20Customers%20Who%20Bought%20All%20Products.sql)
6263
- [1070. Product Sales Analysis III](./leetcode/medium/1070.%20Product%20Sales%20Analysis%203.sql)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Question 570. Managers with at Least 5 Direct Reports
3+
Link: https://leetcode.com/problems/managers-with-at-least-5-direct-reports/description/
4+
5+
Table: Employee
6+
7+
+-------------+---------+
8+
| Column Name | Type |
9+
+-------------+---------+
10+
| id | int |
11+
| name | varchar |
12+
| department | varchar |
13+
| managerId | int |
14+
+-------------+---------+
15+
id is the primary key (column with unique values) for this table.
16+
Each row of this table indicates the name of an employee, their department, and the id of their manager.
17+
If managerId is null, then the employee does not have a manager.
18+
No employee will be the manager of themself.
19+
20+
21+
Write a solution to find managers with at least five direct reports.
22+
23+
Return the result table in any order.
24+
*/
25+
26+
WITH five_direct AS (
27+
SELECT
28+
managerId,
29+
COUNT(managerId) AS manager
30+
FROM Employee
31+
GROUP BY managerId
32+
)
33+
34+
SELECT e.name
35+
FROM Employee AS e
36+
LEFT JOIN
37+
five_direct AS f
38+
ON e.id = f.managerId
39+
WHERE f.manager >= 5

0 commit comments

Comments
 (0)