The Employee table lists every employee and the id of their direct manager. Return the name of every manager who has at least five direct reports.
Input Table(s)
Employee (primary key id)
| Column | Type | Meaning |
|---|
id | INT | Primary key. One row per employee. |
name | VARCHAR(255) | Employee name. Not unique. |
department | VARCHAR(255) | Department of the employee. |
managerId | INT | id of the employee's direct manager, or NULL for a top-level employee. |
Output Contract
-
One column:
name
.
-
One row per manager with at least five direct reports.
-
Sort by the manager's
id
ascending (the
id
itself is not returned).
Example
Employee
| id | name | department | managerId |
|---|
| 101 | John | A | NULL |
| 102 | Dan | A | 101 |
| 103 | James | A | 101 |
| 104 | Amy | A | 101 |
| 105 | Anne | A | 101 |
| 106 | Ron | B | 101 |
Expected output
John has 5 direct reports (Dan, James, Amy, Anne, Ron), so John is returned. Ron is in a different department but still reports to John.
Constraints and Clarifications
-
The table has 1 to 10,000 rows.
-
managerId
is NULL for top-level employees. No employee is their own manager.
-
Count only direct reports, meaning employees whose
managerId
equals the manager's
id
. Reports of reports do not count, and departments play no role.
-
"At least five" includes exactly five.
-
name
is not unique. Two different managers with the same name are separate managers, and each one that qualifies is its own output row.
-
Only managers that have their own row in
Employee
can be returned, since the name comes from that row.