Identify Managers
Start Timer
0:00:00
Given a table of employees, write a query to identify all managers.
A manager is defined as any employee who directly supervises at least one other employee.
Manager Definition:
- An employee is considered a manager if at least one other employee has them listed as their supervisor.
- Each employee has a unique ID, and supervisors are referenced by their employee ID.
Schema:
Input:
Table employees
| Column | Type |
|---|---|
| employee_id | INTEGER |
| name | VARCHAR |
| supervisor_id | INTEGER |
Output:
| Column | Type |
|---|---|
| name | VARCHAR |
Example:
Input:
employees table
| employee_id | name | supervisor_id |
|---|---|---|
| 1 | Alice | NULL |
| 2 | Bob | 1 |
| 3 | Carol | 1 |
| 4 | David | 2 |
| 5 | Eve | NULL |
Output:
| name |
|---|
| Alice |
| Bob |
Explanation:
- Alice is a manager because both Bob and Carol report directly to her (
supervisor_id = 1). - Bob is a manager because David reports directly to him (
supervisor_id = 2). - Eve is not a manager because no employees report to her.
.
.
.
.
.
.
.
.
.
Comments