Reputation: 223
I'm trying to add to a user node an average rating attribute, and assign the value. I can get the userid, and the average successfully with the following cql query.
MATCH (n)-[r:RATES]->(m)
RETURN DISTINCT n.userid as userid, AVG(toFloat(r.rating)) as avgrating
ORDER BY n.userid
How do I go about adding the average to the n (user) node? I've tried a FOREACH with no success.
MATCH p = (n)-[r:RATES]->(m)
FOREACH (n IN nodes(p)| SET n.avgrating = AVG(toFloat(r.rating)))
And also a set
MATCH (n)-[r:RATES]->(m)
SET n.avgrating = AVG(toFloat(r.rating))
RETURN n.userid, n.avgrating)
ORDER BY n.userid;
Upvotes: 1
Views: 147
Reputation: 7790
MATCH (p:Person)-[r:RATES]->()
WITH p, AVG(r.rating) AS avg
SET p.avg_rating = avg
Upvotes: 1