聚合路径上的关系属性

时间:2013-07-31 16:28:39

标签: neo4j cypher

我正试图在MATCH找到的每条路径上获得权重的和。查询如下:

START n=node(10200) 
MATCH p=(n)-[r*1..5]->(m:Facility) 
WITH REDUCE(weights=0, rel IN r : weights + rel.weight) AS weight_sum 
WHERE ALL(n in nodes(p) WHERE 1=length(filter(m in nodes(p) : m=n))) 
RETURN p AS paths, length(p) AS pc,  
(weight_sum / (length(p) * (length(p) / 2))) AS sp;

每次我跑,我都会......

Unknown identifier `p`

如果我删除了我的WITH行(以及weight_sum RETURN值),查询就知道'p'是什么并且执行得很好。我的查询是否存在“p”值丢失的问题?是否有更好的替代方法来获得这些关系属性的SUM?

1 个答案:

答案 0 :(得分:4)

您可以通过WITH:

将“p”传递给查询的下一部分
START n=node(10200) 
MATCH p=(n)-[r*1..5]->(m:Facility) 
WITH REDUCE(weights=0, rel IN r : weights + rel.weight) AS weight_sum, p
WHERE ALL(n in nodes(p) WHERE 1=length(filter(m in nodes(p) : m=n))) 
RETURN p AS paths, length(p) AS pc,  
(weight_sum / (length(p) * (length(p) / 2))) AS sp;