2
很容易識別具有一定數量傳入或傳出關係的節點,但我想識別連接冗餘,因此我想獲得一組具有多於一個關係的節點。如何在neo4j中使用密碼找到彼此之間具有多種關係的節點?
僞代碼,遺憾的是不返回任何結果:
MATCH (n1)-[r]-(n2)
with distinct n1,r,n2, count(r) as sstcount
where sstcount > 1
RETURN n1,r,n2
很容易識別具有一定數量傳入或傳出關係的節點,但我想識別連接冗餘,因此我想獲得一組具有多於一個關係的節點。如何在neo4j中使用密碼找到彼此之間具有多種關係的節點?
僞代碼,遺憾的是不返回任何結果:
MATCH (n1)-[r]-(n2)
with distinct n1,r,n2, count(r) as sstcount
where sstcount > 1
RETURN n1,r,n2
我想我找到了一個解決方案,查詢需要正確鏈接。任何「更好的解決方案」高度讚賞。
MATCH (n1)-[r]-(n2)
WITH distinct n1,n2, count(r) as sstcount
MATCH (n1)-[r]-(n2)
where sstcount>1
return n1,r,n2
試試這個來代替:
MATCH (n1)-[r]-(n2)
WHERE id(n1) < id(n2) // so we avoid matching to the same nodes in swapped order
WITH n1,n2, count(r) as sstcount
WHERE sstcount > 1
RETURN n1, n2