Domanda

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;
È stato utile?

Soluzione

MATCH (p:Person)-[r:RATES]->()
WITH p, AVG(r.rating) AS avg
SET p.avg_rating = avg
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top