I have a table for self-regulation with content like this:
Self-referencing parent table
ID ParentID Name
---------------------
1 John
2 1 Mike
3 2 Erin
4 1 Janie
5 Eric
6 5 Peter
The tree hierarchy should look like this:
And the child table in which the sheet of the parent table is stored is as follows:
ID Sales
3 100
3 100
4 200
4 200
6 300
6 300
6 300
I am trying to collapse the sum from a node sheet to a hierarchy so that it returns as ..
ID Name Sum
1 John 800
2 Mike 200
3 Erin 200
4 Janie 400
5 Eric 900
6 Peter 900
Any ideas how to achieve this in sql 2008? Thanks in advance.
source
share