nightshadz
asked on
SQL - Ordering Supervisor Hierarchy
I have a supervisor table with three columns which looks similar to the one below. I need to reformat the reporting structure in a specific format which is defined below. It basically starts out at the top level and any direct report to that person is -1. Hope this makes sense. Thanks in advance!
How can I write a query to output the structure so it looks like this:
Person1 = “CEO -0”
Person6 = “CEO -1”
Person7 = “CEO -2”
Person8 = “CEO -3”
Person2 = “CEO -1”
Person3 = “CEO -2”
Person4 = “CEO -3”
Person5 = “CEO -3”
NAME SUPERVISOR_ID REPORTS_TO_ID
Person1 2 1
Person2 12 2
Person3 37 12
Person4 62 37
Person5 154 37
Person6 144 2
Person7 168 144
Person8 69 168
How can I write a query to output the structure so it looks like this:
Person1 = “CEO -0”
Person6 = “CEO -1”
Person7 = “CEO -2”
Person8 = “CEO -3”
Person2 = “CEO -1”
Person3 = “CEO -2”
Person4 = “CEO -3”
Person5 = “CEO -3”
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER