Interview Questions/SQL/Manager With at Least 5 Direct Reports

Manager With at Least 5 Direct Reports

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Manager With at Least 5 Direct Reports

You have an Employee table where each employee may have a manager (identified by managerId). A manager is also an employee in the same table. Write a SQL query to find the names of managers who have at least 5 direct reports. Return the result in any order.

Examples

Example 1

John (id=101) manages Dan, James, Amy, Anne, and Ron - that is 5 direct reports, so John qualifies.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

query.sql