0

我是 neo4j 的新手,我有以下情况

match (c:customer{id:'12345'})-[r:buys]->(b:item)
with b,b.total as z
match (b)-[same:*1..z)]->(d)
return d

在上面的查询中z是一个整数,但是上面的查询不起作用,

我将不胜感激所有的帮助和建议,在此先感谢

4

1 回答 1

1

您不能将变量用于路径长度。一种解决方法是:

match (c:customer{id:'12345'})-[r:buys]->(b:item)
with b,b.total as z
match p=(b)-[same:*1..9999)]->(d)
where length(p)=z 
return d

将 9999 替换为适合您用例的全局上限。请注意,这可能效率很低。在这种情况下,最好发送 2 个 Cypher 语句:

match (c:customer{id:'12345'})-[r:buys]->(b:item) return id(b), b.total as z

对于第二个查询,通过字符串连接插入 z 的值:

match (b)-[same:*1..<z>)]->(d) return d
于 2014-05-03T12:26:56.290 回答