21
votes

I am using Neo4j 2.0 and using the following query to find out the count of number of a particular relationship from a particular node.

I have to check the number of relationships named "LIVES" from a particular node PERSON.

My query is:

match (p:PERSON)-[r:LIVES]->(u:CITY) where count(r)>1  
return count(p);

The error shown is:

SyntaxException: Invalid use of aggregating function count(...)

How should I correct it?

1

1 Answers

40
votes

What you want is a version of having? People living in more than one city?

MATCH (p:PERSON)-[:LIVES]->(c:CITY) 
WITH p,count(c) as rels, collect(c) as cities
WHERE rels > 1
RETURN p,cities, rels