我有一个树数据结构,其中数据在叶节点输入。我想要做的是将这些数据汇总到树中,例如对于树中的任何节点,将其下面的所有数据相加。
是否有任何巧妙的方法可以使用图形数据库来做到这一点?
最佳答案
在 cypher (neo4j) 中,您可以执行以下操作:
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/
关于neo4j - 将数据总结为树形数据结构(在图形数据库中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15590800/