Senior Manager Direct Reports
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:
Output:
Input:
| employees | ||
|---|---|---|
| employee_id | employee_name | manager_id |
| 1 | Alice | null |
| 2 | Bob | 1 |
| 3 | Grace | 1 |
| 4 | Jack | 1 |
| 5 | Charlie | 2 |
| 6 | Diana | 2 |
| 7 | Edward | 3 |
| 8 | Fiona | 4 |
| 9 | Henry | 4 |
| 10 | Karen | 4 |
| 11 | Leo | 5 |
| 12 | Mike | 6 |
| 13 | Nancy | 7 |
| 14 | Oscar | 8 |
| 15 | Paul | 9 |
| 16 | Quinn | 10 |
| direct_report_count | senior_manager_name |
|---|---|
| 3 | Jack |
| 2 | Bob |
| 1 | Grace |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Amazon