neo4j - 将数据总结为树形数据结构(在图形数据库中)

标签 neo4j graph-databases orientdb

我有一个树数据结构,其中数据在叶节点输入。我想要做的是将这些数据汇总到树中,例如对于树中的任何节点,将其下面的所有数据相加。

是否有任何巧妙的方法可以使用图形数据库来做到这一点?

最佳答案

在 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/

相关文章:

Neo4J 返回带有空格的列别名 (AS) 名称,这可能吗?

Neo4j:在 Web 界面中提供密码参数

traversal - 使用 OrientDB 中的边属性查找顶点之间的路径

graph-databases - 在处理可选字段时,在 gremlin 中使用注入(inject)进行长遍历

neo4j - 在图形数据库中保留节点和关系历史

java - 如何使用 Java 文档 API 为 OrientDB 数据库创建自动递增索引/序列?

orientdb - systemd 在 Ubuntu 16.04 上启动后立即停止 OrientDB

c# - Neo4j 单实例连接

mysql - GraphDatabase (Neo4J) vs Relational database (MySql) - 查询特定表的特定列

azure-cosmosdb - TinkerPop/CosmosDB 中的命令式匹配