24

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?

Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
poorvank
  • 7,524
  • 19
  • 60
  • 102

1 Answers1

47

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
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • I have a similar problem with a complexity where aggregate is not working, any idea any? https://stackoverflow.com/questions/49841856/neo4j-cypher-query-multiple-aggregates – Srinath Ganesh Apr 15 '18 at 12:35
  • this isnt very performant over a large data set... – Matt Jan 20 '22 at 21:50