Practice Interview Questions
| Question | Status |
|---|---|
Given a table of employees with their respective managers, write a SQL query to generate a report that displays the name of each employee along with the name of their manager (if any) and the number of direct reports each manager has.
To clarify, the manager_name column may have NULL values for top-level managers (those with no manager_id). These employees have no manager, so their manager_name should be blank or NULL in the output.
employees table:
| Column Name | Description |
|---|---|
| id | Unique identifier for each employee |
| name | Name of the employee |
| manager_id | Identifier of the employee's manager |
| manager_name |
|---|
| direct_reports |
|---|
| Alice | Dave | 5 |
| Bob | Carol | 3 |
| Carol | Dave | 5 |
Given a table of employees with their respective managers, write a SQL query to generate a report that displays the name of each employee along with the name of their manager (if any) and the number of direct reports each manager has.
To clarify, the manager_name column may have NULL values for top-level managers (those with no manager_id). These employees have no manager, so their manager_name should be blank or NULL in the output.
employees table:
| Column Name | Description |
|---|---|
| id | Unique identifier for each employee |
| name | Name of the employee |
| manager_id | Identifier of the employee's manager |
| employee_name | manager_name | direct_reports |
|---|---|---|
| Alice | Dave | 5 |
| Bob | Carol | 3 |
| Carol | Dave | 5 |