<aside> 💡
This project identifies managers who have at least five direct reports. The solution demonstrates SQL skills in self-joins, grouping, and filtering aggregate results to provide insights into organizational structures.
</aside>
managerId is NULL, the employee does not have a manager.The goal is to find managers who have five or more employees reporting directly to them.
The query uses a self-join to link employees with their managers and then aggregates the results to count the number of direct reports for each manager.
SELECT e1.name
FROM Employee e1
INNER JOIN Employee e2
ON e1.id = e2.managerId
GROUP BY e1.id
HAVING COUNT(e2.managerId) >= 5;
INNER JOIN Employee e2 ON e1.id = e2.managerId links each manager (e1) to their direct reports (e2).GROUP BY e1.id groups the results by manager to calculate metrics for each manager.COUNT(e2.managerId) counts the number of employees directly reporting to each manager.HAVING COUNT(e2.managerId) >= 5 ensures only managers with five or more direct reports are included.