staff has one row per employee (employee_id, manager_id, title); manager_id references another employee and is NULL at the top. An employee counts as a manager when at least one employee reports to them (the title column is informational only and must not be used). Return every manager who has at least one direct report who is also a manager, together with the number of such direct reports. Output columns: manager_id, manager_reports. Order by manager_id ascending.
| Column | Type |
|---|---|
| employee_id | INTEGER |
| manager_id | INTEGER |
| title | TEXT |
| employee_id | manager_id | title |
|---|---|---|
| 1 | NULL | Director |
| 2 | 1 | supervisor |
| 3 | 2 | Analyst |
| 4 | 1 | supervisor |
| 5 | 4 | Analyst |
| 6 | 2 | Analyst |
| manager_id | manager_reports |
|---|---|
| 1 | 2 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Dormant Then Returning Members · Infrastructure Active Hours ›
{{ 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.