문제

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;
도움이 되었습니까?

해결책

MATCH (p:Person)-[r:RATES]->()
WITH p, AVG(r.rating) AS avg
SET p.avg_rating = avg
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top