The tree is unlimited depth. example:
+----+-------+--------------------+
| id | name | parent_id | value |
+----+-------+--------------------+
| 1 | test1 | | 0 |
| 2 | test2 | 1 | 0 |
| 3 | test3 | 2 | 5 |
| 4 | test4 | 1 | 0 |
| 5 | test5 | 4 | 5 |
| 6 | test6 | 4 | 0 |
| 7 | test7 | 6 | 10 |
+----+-------+--------------------+
I want to get the total value of one's children. just like this:
+----+-------+--------------------+
| id | name | parent_id | value |
+----+-------+--------------------+
| 1 | test1 | | 20 | = test2.value + test4.value
| 2 | test2 | 1 | 5 | = test3.value
| 3 | test3 | 2 | 5 |
| 4 | test4 | 1 | 15 | = test5.value + test6.value
| 5 | test5 | 4 | 5 |
| 6 | test6 | 4 | 10 | = test7.value
| 7 | test7 | 6 | 10 |
+----+-------+--------------------+
any suggestion ? Thanks!