D
D
drboboev2017-05-22 10:51:17
PHP
drboboev, 2017-05-22 10:51:17

How to calculate the sum of child elements by field (Nested Sets)?

Good afternoon.
There is a tree in the database based on the Nested Sets model. I deduce a tree, in other table values ​​communication one-to-many are written down. Values ​​are entered every day at the bottom of the tree. You need to make a query that will get the entire tree from the database and sum up all the values ​​of the descendants on the parent.
Example:
Parent 1: 25pcs (5+15+5) Child
1.1
: 5pcs Child 1.2: 15pcs Child
1:3: 5pcs Parent 2 :
45pcs (20+25 ) 5pcs Descendant 2.1.2: 15pcs Descendant 2.2: 25pcs There can be up to 10 such levels and there will be a large number of tree nodes. Those. you need an optimal solution so that the query is executed as quickly as possible. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
drboboev, 2017-05-22
@drboboev

An example of a tree for clarity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question