For every employee who manages at least one person, return `emp_name`, `direct_reports`, `total_reports` (everyone below them at any level) and `max_depth` (number of levels below them; a manager with only direct reports has depth 1). Order by `total_reports` DESC, then `emp_name`.
| Column | Type |
|---|---|
| emp_id | INTEGER |
| emp_name | TEXT |
| manager_id | INTEGER |
| emp_id | emp_name | manager_id |
|---|---|---|
| 1 | Asha | NULL |
| 2 | Bilal | 1 |
| 3 | Chen | 1 |
| 4 | Divya | 2 |
| 5 | Elan | 2 |
| 6 | Farah | 4 |
| 7 | Gopal | 3 |
| emp_name | direct_reports | total_reports | max_depth |
|---|---|---|---|
| Asha | 2 | 6 | 3 |
| Bilal | 2 | 3 | 2 |
| Chen | 1 | 1 | 1 |
| Divya | 1 | 1 | 1 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Monthly Occupancy with Stays Split Across Months · People You May Know by Mutual Connections ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.