I have a tree data structure in which data is entered at the leaf nodes. What I want to do is sum this data up the tree e.g. for any node in the tree, sum up all the data underneath it.
Are there any clever ways to do this using a graph database?
In cypher (neo4j), you can do something like this:
start n=node:node_auto_index(id={id})
match n-[:parent_of*]->child
where not(child-[:parent_of]->()) // where the child doesn't have children (leaf)
return n, sum(child.val);
http://wes.skeweredrook.com/cypher-summing-data-up-a-tree-leaf-nodes/