[英]Neo4j cypher: find node at detph 2, without circular path
我想找到距離當前節點2的所有節點:
eg:
1<->2
2<->3
1->3
2->4
來自節點1的這種A應該找到節點4
我已經嘗試過此查詢,但是它遇到了循環路徑:
start n=node({startid})
match n--> m
with distinct m as f1
match f1-->m
with distinct m as f2
return count(f2)
實際上,它還在距離2處找到了1,2,3,4作為節點,而沒有考慮距離1應該在距離0、2,3距離1上,而只有4在距離2處。
有什么建議嗎?
您的意思是這樣的嗎:
START n=node({startid})
MATCH (n)-[*..2]->m
RETURN m
*之后,您可以定義路徑的長度。 * .. 2表示:長度在零到2之間。
START n=node({startid})
MATCH (n)-[*2]->m
WHERE n <> m
RETURN m
對於固定長度2,WHERE將確保不返回n。
有關完整的文檔,請訪問: http : //docs.neo4j.org/chunked/milestone/query-match.html#match-variable-length-relationships
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.