Consider the following flattened hiearchy table for employees
ParentID ParentName ChildLevel ChildID ChildName
01 Ann 1 01 Ann
01 Ann 2 02 Brenda
01 Ann 3 03 Carl
01 Ann 2 04 Dave
01 Ann 3 05 Ebert
02 Brenda 4 03 Carl
04 Dave 4 05 Ebert
The ChildLevel indicates the tree level (Hiearchy). So Ann is the top level manager. Brenda and Dave work for Ann. Carl works for Brenda, Ebert works for Dave.
I want sql that will return all of these people grouped properly so in a report it will look like this:
Ann
Brenda
Carl
Dave
Ebert
Basically a drill-down report. So I need a NodeLevel and the name so I know how to group them. The root id for Ann is passed in.
I need a solution for both oracle and sql server.
Start Free Trial