Reputation: 1304
I want to make a database where a :Person can rate a :Movie on a criteria. I want the criterias to be dynamic :
For instance John could rate Titanic 3.8/5 for the acting and 4/5 for the special effects. Anna could rate Titanic 4/5 on acting and 5/5 on decor
For now, my strategy is :
My question is : Is there a way to cypher query the ratings of a movie aggregating the the grades by criteria?
This query on the movie Titanic should return something like:
[ {criteria: acting, avg_m.grade : 3.9},{criteria: special effects, avg_m.grade : 4},{criteria: decor, avg_m.grade : 5}]
Upvotes: 1
Views: 420
Reputation: 39915
You need to use Cypher's avg
function. Assuming you want to have averages on a movie with a title of "abc":
MATCH (:Movie {title:'abc'})<-[r:Rate]-()
RETURN r.criteria as criteria, avg(r.grade) as avg_grade
Upvotes: 2