neo4j select nodes that have at least n relations

会有一股神秘感。 提交于 2019-12-11 15:47:38

问题


I'm trying to build a cypher query that select people that live in a city and countries that those cities belong to.

this is what I have at them moment:

MATCH (p:Person)-[r:LiveIn]-(city:City) 
WHERE  s.name= "a" OR s.name= "b" OR ... 
MATCH (city)-[:IsIn]-(country:Country) 
RETURN city,country,person

but what I really want to say is :

"select cities that have atleast 5 of those people (p) liveIn them"

I'm not quite sure how to tackle this.

Any suggestions?


回答1:


Try this one:

MATCH (p:Person)-[r:LiveIn]->(city:City)-[:IsIn]->(country:Country)
WHERE  s.name in ["a", "b",...]
WITH city, country, count(p) as c, collect(p) as persons
WHERE c>=5
RETURN city,country,persons


来源:https://stackoverflow.com/questions/30376983/neo4j-select-nodes-that-have-at-least-n-relations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!