Managers with at Least 5 Direct Reports

Quick Overview

Write a SQL query that returns the name of every manager with at least five direct reports, using an employee table where each row points to its manager. It tests joining a table to itself, counting per group, and handling NULL manager ids and managers who share a name.

Managers with at Least 5 Direct Reports

Company: Adyen

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

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. ```hint Identify the manager Two managers can share a name, so choose carefully which column identifies a manager when you count. ``` ### 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 | name | |---| | John | 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.

Overview: Write a SQL query that returns the name of every manager with at least five direct reports, using an employee table where each row points to its manager. It tests joining a table to itself, counting per group, and handling NULL manager ids and managers who share a name.

Adyen logo
Adyen
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

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)

ColumnTypeMeaning
idINTPrimary key. One row per employee.
nameVARCHAR(255)Employee name. Not unique.
departmentVARCHAR(255)Department of the employee.
managerIdINTid 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

idnamedepartmentmanagerId
101JohnANULL
102DanA101
103JamesA101
104AmyA101
105AnneA101
106RonB101

Expected output

name
John

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.