SQL INTERVIEW QUESTION | Find the group number in a given employee hierarchy

 DROP TABLE IF EXISTS #OrganizationChart;

GO


CREATE TABLE #OrganizationChart

(

ManagerID   VARCHAR(1),

EmployeeID  VARCHAR(1) NOT NULL PRIMARY KEY

);

GO


INSERT INTO #OrganizationChart (ManagerID, EmployeeID) VALUES

(NULL, 'A'),

('A', 'B'),

('A', 'C'),

('B', 'D'),

('B', 'E'),

('D', 'G'),

('C', 'F');

GO


 

  SELECT * FROM #OrganizationChart

Comments

Popular posts from this blog

50 Essential SQL Questions to Land Your Dream Job

How to find all the customers who placed orders on three consecutive days | SQL Scenario questions

ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs