[英]Limiting a Neo4j cypher query results by sum of relationship property
[英]Neo4j cypher query to return relationship property and sum of all matching relationship properties
我正在尝试为Neo4j中的Cypher查询匹配的所有关系返回一个关系属性(称为proportion
)加上该属性的总和。 我已经走了这么远:
START alice=node(3)
MATCH p=(alice)<-[r:SUPPORTED_BY]-(n)
RETURN reduce(total=0, rel in relationships(p): total + rel.proportion), sum(r.proportion) AS total;
返回:
+-----------------+
| reduced | total |
+-----------------+
| 2 | 2 |
| 1 | 1 |
+-----------------+
我期待的地方:
+-----------------+
| reduced | total |
+-----------------+
| 2 | 3 |
| 1 | 3 |
+-----------------+
作为Cypher的初学者,我不太确定如何处理此查询。 我显然没有正确使用reduce
。 任何意见,将不胜感激。
您需要使用WITH
将查询分为两部分:
。
START alice=node(3)
MATCH alice<-[r:SUPPORTED_BY]-()
WITH sum(r.proportion) AS total
MATCH alice<-[r:SUPPORTED_BY]-(other)
RETURN other.name, r.proportion, total
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.