I have a table
Node | NoteParent | Num
A | Root | 10
B | A | 20
C | A | 30
G | B | 40
D | B | 50
E | G | 70
F | C | 60
I have a question that how I can use CTE to Sum the Num of node depend on the link of its to another node. For example, I have node B have Num is 20, node B is the parent of node G and node D, also node G is the parent of node E so I will use all the num of related nodes 20(B) + 40(G) + 50(D) + 70(E) = 180
The result would be:
Node | NoteParent | Num | SUM
A | Root | 10 | 280
B | A | 20 | 180
C | A | 30 | 90
G | B | 40 | 110
D | B | 50 | 50
E | G | 70 | 70
F | C | 60 | 60