Managers with at least 5 Direct Reports

4pts
Meta

Problem Statement

Organizational health is often monitored by looking at management spans of control. You need to identify managers who have a high number of direct reports.

Write an SQL query to report the managers who have at least five direct reports.

Rules:

  • A direct report is an employee who has the manager's ID in their managerId column.
  • If a manager has fewer than five reports, they should not be included.
  • Return the result table containing only the name column.
  • Results must be sorted by name in ascending order.
Tests your understanding of
Basic SQL, Self Join, Aggregation and HAVING Clause

Input Tables

employee
id(INTEGER)name(VARCHAR)department(VARCHAR)managerId(INTEGER)
101JohnAnull
102DanA101
103JamesA101
104AmyA101
105AnneA101
106RonB101

Expected Output

name(VARCHAR)
John

Tags

MediumBasic SQLSelf JoinAggregationHAVING Clause
10-15 min
50%

Hints