Back to questions

Senior Managers Google SQL Interview Question

Senior Managers

Google SQL Interview Question

Assume we have a table of Google employees with their corresponding managers.

A manager is an employee with a direct report. A senior manager is an employee who manages at least one manager, but none of their direct reports is senior managers themselves. Write a query to find the senior managers and their direct reports.

Output the senior manager's name and the count of their direct reports. The senior manager with the most direct reports should be the first result.

Assumption:

  • An employee can report to two senior managers.

Table:

Column NameType
emp_idinteger
manager_idinteger
manager_namestring

Example Input:

emp_idmanager_idmanager_name
1101Duyen
1011001Rick
1031001Rick
10011008John

Example Output:

manager_namedirect_reportees
Rick1

Rick is a senior manager who has one manager directly reporting to him, which is employee id 101.

The dataset you are querying against may have different input & output - this is just an example!

Input

Output