1882. The Number of Employees Which Report to Each Employee
My accepted SQL solution to LeetCode problem 1882, The Number of Employees Which Report to Each Employee, running in 1497ms.
- Difficulty: Easy
- SQL
- Runtime 1497ms
- Memory 0.0B
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
SQL
Accepted on LeetCode — runtime 1497ms, memory 0.0B, accepted 2025-12-31.
SELECT e1.employee_id, e1.name,
COUNT(e2.employee_id) AS reports_count,
ROUND(AVG(e2.age), 0) AS average_age
FROM Employees e1
JOIN Employees e2 ON e1.employee_id = e2.reports_to
GROUP BY e1.employee_id
ORDER BY e1.employee_id