Senior Manager Direct Reports
Amazon 🧠 Hard SQL
Beginner Mode

Objective

You are given a table of Amazon employees with their corresponding managers. Each row represents a reporting relationship between an employee and their manager.

Table Schema:

The employees table:

Column Type Description
employee_id integer Unique ID for the employee
employee_name text Name of the employee
manager_id integer ID of the employee's direct manager (NULL for top-level)

Task Requirements:

  • A manager is an employee who has at least one direct report
  • A senior manager is an employee who manages at least one manager, but none of their direct reports are senior managers themselves
  • Find all senior managers and count their direct reports
  • An employee can report to two senior managers
  • Order the results by direct report count in descending order, then by name alphabetically



Output columns: senior_manager_name, direct_report_count

Examples

Example 1:

Input:

employees
employee_idemployee_namemanager_id
1Alicenull
2Bob1
3Grace1
4Jack1
5Charlie2
6Diana2
7Edward3
8Fiona4
9Henry4
10Karen4
11Leo5
12Mike6
13Nancy7
14Oscar8
15Paul9
16Quinn10

Output:
direct_report_countsenior_manager_name
3Jack
2Bob
1Grace
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →