Reputation: 1103
Unable to write a query to set avg rating for a director.
Also, can't figure out how to use FOREACH
in this case to avoid Invalid use of aggregating function
, Type mismatch: expected Collection<T> but was Node
errors.
Avg Rating of a director = Avg(Rating of all its movies)
Example query
MATCH (d:Director)
WITH d
MATCH (d)-[:Directed]->(m:Movie)
SET d.avg_rating = AVG(toFloat(COLLECT(m.rating)))
Please help out.
Upvotes: 0
Views: 138
Reputation: 2996
You Can directly use
MATCH (d:Director)-[:Directed]->(m:Movie)
SET d.avg_rating = AVG(toFloat(m.rating))
Upvotes: 2
Reputation: 19373
The toFloat would apply directly to m.rating, and AVG doesn't need the COLLECT:
MATCH (d:Director)-[:Directed]->(m:Movie)
SET d.avg_rating = AVG(toFloat(m.rating))
(I also dropped the superfluous match d:Director, which has nothing to do with your error however)
Upvotes: 2