I have two related tables about customers called Tree and Order. A Tree Table contains hierarchy of customers which have four levels. So the columns in this table are four: level1, level2, level3 and four(all values are the customer ids on that level). As you can see in the table , in some cases customer of level1 and level2 can be the same(C100). The second table total amount of order of each customer(if they order).
Now I want to create matrix of the four level with "family total order"
Level1 - (level1 + level2 + level3 + level4) of its family under it
Level2 - (level2 + level3 + level4) of its family under it