[英]Finding Nodes with lots of relations pointing to it in neo4j using cypher
我有一個neo4j數據庫,其節點遵循此結構
[a:article_id] -[r:about_place]-> [l:location]
現在我想找到article_id,位置對,其中位置具有很多傳入關系(例如> 4)
MATCH ()-[r:about_place]->(n)
WITH n,count(r) as rel_cnt
where rel_cnt > 4
RETURN n.name,rel_cnt;
這有效,我可以根據需要獲取位置列表。
但是我現在也希望從該關系中獲取所有傳入的文章,例如中國所指的5個文章ID。
像這樣
MATCH (a)-[r:about_place]->(n)
WITH a,n,count(r) as rel_cnt
where rel_cnt > 4
RETURN a.title,n.name,rel_cnt;
但這將返回0行。 我猜是因為現在(a,n)組合在group子句中使用,這使得count(r)在每一行中始終為1。 我在一次談話中看到,這是count(*)子句默認工作的方式。
我認為一種解決方案是將這些結果鏈接起來並進行新的查詢,但是對於我來說,我不知道該如何做。 任何想法或鏈接也會有所幫助。
我不確定是否有比這更好的方法:
MATCH ()-[r:about_place]->(n)
WITH n, count(r) as rel_cnt
WHERE rel_cnt > 4
MATCH (a)-[r:about_place]->(n)
RETURN a.title,n.name,rel_cnt;
另外,請注意:
MATCH ()-[r:about_place]->(n:location)
)以獲得更好的性能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.