1731. The Number of Employees Which Report to Each Employee
Description
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| employee\_id | int |
| name | varchar |
| reports\_to | int |
| age | int |
+-------------+----------+
employee\_id is the primary key for this table.
This table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports\_to is null). Employees table:
+-------------+---------+------------+-----+
| employee\_id | name | reports\_to | age |
+-------------+---------+------------+-----+
| 9 | Hercy | null | 43 |
| 6 | Alice | 9 | 41 |
| 4 | Bob | 9 | 36 |
| 2 | Winston | null | 37 |
+-------------+---------+------------+-----+
Result table:
+-------------+-------+---------------+-------------+
| employee\_id | name | reports\_count | average\_age |
+-------------+-------+---------------+-------------+
| 9 | Hercy | 2 | 39 |
+-------------+-------+---------------+-------------+
Hercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.ac
Last updated