Skip to content

Latest commit

 

History

History

Company Structure

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Company Structure

Star Badge View Main Folder View Repositories View My Profile


🛠️ Problem Statement

Table Name : company

Column Name Type
employee varchar(10)
manager varchar(10)
  • employee is the primary key for this table.

This table provides employee name and their manager name.

Given graph shows the hierarchy of employees in a company. Write an SQL query to split the hierarchy and show the employees corresponding to their team.


Assumption: Assume that the total number of teams are the same as the number of people reporting to the person at top.
Return the result table in any order.

The query result format is in the following example:

Input
Table Name : company

employee manager
Elon
Ira Elon
Bret Elon
Earl Elon
James Ira
Drew Ira
Mark Bret
Phil Mark
Jon Mark
Omid Earl
Output
team members
Team 1 Elon ,Bret, Jon, Mark, Phil
Team 2 Elon ,Earl, Omid
Team 3 Elon ,Drew, Ira, James