<aside> 💡

Project Overview:

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>


Problem Description:

Table: Employee

The goal is to find managers who have five or more employees reporting directly to them.


Solution:

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;


Explanation:

  1. Self-Join:
  2. Grouping by Manager:
  3. Counting Direct Reports:
  4. Filtering Managers: