Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f1f0a47

Browse files
add 570
1 parent 8f85f7a commit f1f0a47

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ Your ideas/fixes/algorithms are more than welcome!
610610
|580|[Count Student Number in Departments](https://leetcode.com/problems/count-student-number-in-departments/)|[Solution](../master/database/_580.sql) | || Medium | Left Join
611611
|577|[Employee Bonus](https://leetcode.com/problems/employee-bonus/)|[Solution](../master/database/_577.sql) | || Easy |
612612
|574|[Winning Candidate](https://leetcode.com/problems/winning-candidate/)|[Solution](../master/database/_574.sql) | || Medium |
613+
|570|[Managers with at Least 5 Direct Reports](https://leetcode.com/problems/managers-with-at-least-5-direct-reports/)|[Solution](../master/database/_570.sql) | || Medium |
613614
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/)|[Solution](../master/database/_197.sql)| O(n^2)|O(n) | Easy|
614615
|196|[Delete Duplicate Emails](https://leetcode.com/problems/delete-duplicate-emails/)|[Solution](../master/database/_196.sql)| O(n^2)|O(n) | Easy|
615616
|184|[Department Highest Salary](https://leetcode.com/problems/department-highest-salary)|[Solution](../master/database/_184.sql)| O(n^2)|O(n) | Medium|

database/_570.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--570. Managers with at Least 5 Direct Reports
2+
--The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
3+
--
4+
--+------+----------+-----------+----------+
5+
--|Id |Name |Department |ManagerId |
6+
--+------+----------+-----------+----------+
7+
--|101 |John |A |null |
8+
--|102 |Dan |A |101 |
9+
--|103 |James |A |101 |
10+
--|104 |Amy |A |101 |
11+
--|105 |Anne |A |101 |
12+
--|106 |Ron |B |101 |
13+
--+------+----------+-----------+----------+
14+
--Given the Employee table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:
15+
--
16+
--+-------+
17+
--| Name |
18+
--+-------+
19+
--| John |
20+
--+-------+
21+
--Note:
22+
--No one would report to himself.
23+
24+
select Name from Employee as Name where Id in
25+
(select ManagerId from Employee group by ManagerId having count(*) >= 5)
26+
;

0 commit comments

Comments
 (0)