Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count the number of relationships in Neo4j

Tags:

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?

like image 755
poorvank Avatar asked Mar 12 '14 09:03

poorvank


People also ask

Which query is used to return the count of the relationship for a node?

Using count(*) to return the number of nodes. The function count(*) can be used to return the number of nodes; for example, the number of nodes connected to some node n . The labels and age property of the start node n and the number of nodes related to n are returned.

What are relationships in Neo4j?

The Neo4j property graph database model consists of: Nodes describe entities (discrete objects) of a domain. Nodes can have zero or more labels to define (classify) what kind of nodes they are. Relationships describes a connection between a source node and a target node.


1 Answers

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 
like image 93
Michael Hunger Avatar answered Dec 11 '22 10:12

Michael Hunger