Prepin
Log in

Count of Direct Reports

Approach / Explanation

This question requires you to utilize SQL to determine the number of direct reports for a particular employee. Direct reports are those employees who report immediately to another employee. This relationship is commonly depicted within an organization, where, for instance, one employee may have several subordinates categorized as their direct reports. To address this question, you will need to compose a SQL query. Here are some important considerations for crafting your response: Understand how the reporting hierarchy is structured in the database: this could be represented in a single table where each entry lists an employee along with their direct report, or in two separate tables—one containing employee details and the other detailing reporting relationships. Choose the appropriate functions: To tally the number of direct reports, you can employ the COUNT(*) function. Determine how to group the data: You might need to utilize the GROUP BY clause to organize the information by the manager's name or ID.

Suggested Answer

Assuming the existence of a table named "Employee" in the database, which contains a column called "manager_id" that indicates the manager for every employee, the following SQL query can be used to determine the number of direct reports for each manager: SELECT manager_id , COUNT ( * ) as DirectReports FROM Employee GROUP BY manager_id ; This query counts the number of entries for each manager_id, thereby providing the total number of direct reports each manager has, as identified in the "manager_id" column.

Alternative Answer

In this situation, let's consider a slightly altered structure where the database consists of two tables: an "Employees" table that holds employee information, and a "Reports" table with two columns, "employee_id" and "manager_id," which indicate the reporting hierarchy. The SQL query for this scenario would be: SELECT r . manager_id , COUNT ( * ) as DirectReports FROM Reports r JOIN Employees e ON r . employee_id = e . employee_id GROUP BY r . manager_id ; This query connects the "Employees" and "Reports" tables, groups the results by the manager_id from the "Reports" table, and counts the number of entries (i.e., direct reports) associated with each manager.

Question Details

Difficulty & Category

Medium
sql

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.