Search code examples
facebook-graph-apineo4jgraphqlcyphergraph-databases

Do we have 'groupby' clause in Neo4j?


I have written the below query to retrieve movie and corresponding rating:

match (rvwr:Person)-[r:REVIEWED]->(m:Movie)
where m.released > 2003
return m.title, sum(r.rating)/count(r) as rating

I want to confirm if there is a need to use anything similar to groupby clause.


Solution

  • No such 'group by' clause in neo4j cypher. Sum is an aggregate function and m.title is not. So cypher will use title as a group by key. Below is the documentation about it.

    https://neo4j.com/docs/cypher-manual/current/functions/aggregating/