commit 0b31c9badf4a2d803fd0f1aabf7d5a842f6308f8 parent 53542dcab5d4a4410323c78d69d5a617b7892d8b Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Sun, 23 Jul 2023 15:15:55 -0500 Completed employees reporting to managers using mySQL Diffstat:
| A | employees-reporting-to-managers/employees-reporting-to-managers.sql | | | 13 | +++++++++++++ |
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/employees-reporting-to-managers/employees-reporting-to-managers.sql b/employees-reporting-to-managers/employees-reporting-to-managers.sql @@ -0,0 +1,13 @@ +--Given a table with all employees +--return all employees who have +--at least one report along with +--the reports name. +SELECT DISTINCT Employees.employee_id, Employees.name, + COUNT(E.name) AS reports_count, + ROUND(AVG(E.age),0) as average_age +FROM Employees +LEFT JOIN Employees as E +ON Employees.employee_id = E.reports_to +WHERE E.employee_id IS NOT NULL +GROUP BY Employees.employee_id +ORDER BY Employees.employee_id