The Number of Employees Which Report to Each Employee

4pts
Meta

Problem Statement

HR teams at Meta need to evaluate management spans and team demographics. For this task, we consider a manager to be any employee who has at least one other employee reporting to them.

Write an SQL query to report the ids and the names of all managers, the number of employees who report directly to them, and the average age of the reports rounded to the nearest integer.

Rules:

  • Only include employees who are managers (have at least one report).
  • The average_age must be rounded to the nearest integer.
  • Return the columns: employee_id, name, reports_count, and average_age.
  • Results must be sorted by employee_id in ascending order.
Tests your understanding of
Basic SQL, Self Join, Aggregation, Rounding and Math Functions

Input Tables

employees
employee_id(INTEGER)name(VARCHAR)reports_to(INTEGER)age(INTEGER)
9Hercynull43
6Alice941
4Bob936
2Winstonnull37

Expected Output

employee_id(INTEGER)name(VARCHAR)reports_count(INTEGER)average_age(INTEGER)
9Hercy239

Tags

MediumBasic SQLSelf JoinAggregationRoundingMath Functions
15-20 min
55%

Hints