Tuesday, 10 September 2013

Cypher: how to do a COUNT and a MAX/MIN in the same query (same aggregation)

Cypher: how to do a COUNT and a MAX/MIN in the same query (same aggregation)

My model is like this: (wine_critic)-[REVIEW]->(wine_bottle)
A wine_critic can do many reviews of the same wine_bottle, (they don't
know it, it is blind tasting) with each review having a timestamp and a
score
So, I want to get the total number of reviews a wine_bottle has been
reviewed by a certain wine_critic, across with the MAX/MIN score that same
critic has given to that same bottle.
START critic=node:critics('ID:5')
MATCH (critic)-[rev:REVIEW]->(bottle)
WITH critic, bottle, COUNT(rev) as total_reviews
RETURN critic.name, bottle.name, total_reviews
but also, in the same query I want MAX(rev.score) and MIN(rev.score).
Is it possible?

No comments:

Post a Comment