Hello All,
What I'm trying to accomplish is finding the first unique parent in a de-normalized table (left to right view).
For example, take the following table parent/child table:
What I'm trying to accomplish is finding the first unique parent in a de-normalized table (left to right view).
For example, take the following table parent/child table:
Cost Center -Leaf | CENTER_DESC | LEVEL_01 | LEVEL_02 | LEVEL_03 | LEVEL_04 | LEVEL_05 | LEVEL_06 | LEVEL_07 | LEVEL_08 |
1234567 | cc1 | $ | $J | $JA | $JAB | $JABC | $JABCC | $JABCCA | 1234567 |
2222222 | cc2 | $ | $J | $JA | $JAB | $JABC | $JABCD | $JABCDA | 2222222 |
4444444 | cc3 | $ | $D | $DA | $DAA | $DAAB | 4444444 | 4444444 | 4444444 |
7654321 | cc4 | $ | $D | $DA | $DAB | 7654321 | 7654321 | 7654321 | 7654321 |
I've used recursive queries but only used on a normalized table so I can't get my head around how to approach this? If using a recursive query to start the procedure is the best way, I just can't figure out how to fill based on the de-normalized view then weed it down to the result I need. Overall goal: I have to lookup a leaf id value (1st col) in the above table then figure out what level to apply a parent node at a unique level... the rows can vary up to 25k and the levels can go up to 11. Say I was looking up 2222222, then the code would have to traverse through all 'like' parents until it becomes unique... so, in this case 2222222 and 1234567 have the same parent in level_01, level_02, level_03, level_04 and level_05 but differ at level_06 which is the result I'm looking for - looking up cost center 2222222 would result in $JABCD. Likewise, if I was looking up 7654321, then code would have to traverse through 'like' parents... in this case 4444444 has have the same parent in level_01, level_02 and level_03 but differ at level_04 which is the result I'm after - looking up cost center 7654321 would result in $DAB. Now, to even make it worse... there are instances where a cost center is unique (no other siblings in the hierarchy) so I would just want to see the result at Level_03. Thanks, Drew |