Skip to content

1731. The Number of Employees Which Report to Each Employee 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
SELECT
  Manager.employee_id,
  Manager.name,
  COUNT(Employee.employee_id) AS reports_count,
  ROUND(AVG(Employee.age)) AS average_age
FROM Employees AS Manager
INNER JOIN Employees AS Employee
  ON (Employee.reports_to = Manager.employee_id)
GROUP BY 1
ORDER BY 1;