Reputation: 5423
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?
Upvotes: 0
Views: 651
Reputation: 39915
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
Upvotes: 3