You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--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
1
select Name from Employee as Name where Id in
25
2
(select ManagerId from Employee group by ManagerId havingcount(*) >=5)
0 commit comments