cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Do we have 'groupby' clause in Neo4j?

technerd
Node

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.

3 REPLIES 3

czp
Node Link

Groupby is done implicitly by all of the aggregate functions.
This statement is semantically equivalent to groupby for m.title.
Note that all columns not contained within the aggregate function will be the groupby keys.

Thanks.
In that case, how groupby is performed when we have more than 2 columns?

return p2.name, p2.born, sum(r.earnings)/count(p2)

This statement will group by p2.name and p2.born and compute the quotient of the aggregate function sum and count.