I have one mapping table:
Code Parent_code Position
--------------------------------
H1 Null Root
H11 H1 Parent
H111 H11 Parent
H1111 H111 Leaf
H1112 H111 Leaf
One more table which stores amount for leaf level code
Code Amount
-------------
H1111 100
H1112 200
i.e amount is stored at only leaf position
I want to write the query through which the data at leaf level will get rolled up to its parents and ultimately to its root.
Output will look like below
Code Amount
-------------
H1 300
H11 300
H111 300
H1111 100
H1112 200
Also if I select H1 that is root then output should be its children and its grandchildren. Same if I select H11 i should get the output as H111 And children of H111