Hi!

I have table like this, which makes dynamic tree.

Id Parent Cost
1 0 10
2 1 20
3 1 30
4 2 40
5 4 60

Now I would like to calculate for example the total cost of the id 2 (20+40+60=120). How to make the sql statement, which aggregate all the cost of selected id and also from the child objects ? How about grouping by the level of parent?

-Petri-