diff --git a/database/easy/the_number_of_employees_which_report_to_each_employee.sql b/database/easy/the_number_of_employees_which_report_to_each_employee.sql new file mode 100644 index 0000000..ca2ba82 --- /dev/null +++ b/database/easy/the_number_of_employees_which_report_to_each_employee.sql @@ -0,0 +1,11 @@ +-- https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee/ +-- PostgreSQL + +SELECT e1.employee_id, + e1.name, + COUNT(e2.employee_id) AS reports_count, + ROUND(AVG(e2.age)) AS average_age +FROM employees e1 + JOIN employees e2 ON e1.employee_id = e2.reports_to +GROUP BY e1.employee_id, e1.name +ORDER BY e1.employee_id;