What in everyone's opinion is the best representation for a time-bound hierarchy in SQL?
What I mean by this is:
- On any given date you have a normal tree hierarchy
- This hierarchy can change from day to date
- Each child still only has one parent on any given date
Day 1...
Business
|
|-Joe
| |-Happy
| |-Sneezy
| |-Doc(*)
|
|-Moe
|-Bashfull
|-Sleepy
Day 2...
Business
|
|-Joe
| |-Happy
| |-Sneezy
|
|-Moe
|-Doc(*)
|-Bashfull
|-Sleepy
At any time, a child can join the hierarchy for the first time, or leave the hierarchy completely. (For example, new employees, and retired employees.)
The main considerations:
- Updating the hierarchy
- Viewing the whole hierarchy across a date range
- Reporting on whole sub-trees within the hierarchy
- Reporting on whole sub-trees across a date range
I know how I do it at present, but am intrigued as to how other people may do it :)
EDIT
I naively assumed a few considerations so will be more explicit...
- Each 'team' or 'person' will have a unique ID in a dimension table elsewhere
- Other fact tables will use those IDs (storing performance metrics, for example)
- The structure needs to facilitate historical reporting across date ranges
- Use of ETL or triggers to maintain alternative structures Is an option
The generic nature is most important (forming just one part of a generic relational mode), combined with ease of use for driving report (for any part of the tree across any range of dates) and the ability to be updated reliably.