cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

COLLECT the properties of a node and update the values

I need to normalize the math scores that are stored as a property on the node and then update the same property with a normalized value. I have tried this:

MATCH (r:MathScore)
WITH COLLECT(r.score) as myScores
UNWIND myScores as x
WITH myScores, min(x) as n, max(x)-min(x) as den
WITH den, myScores, [val in range(0, size(myScores)-1) | round((myScores[val]-n)*100/den)/100] as g
RETURN g, myScores

The above query gives me the correct results in two lists but I am not able to find a way to update r.score with the values in list g.

Please, can someone help?
Thanks!

1 REPLY 1

MATCH (r:MathScore)
WITH COLLECT(r.score) as myScores, min(r.score) as n, max(r.score)-min(r.score) as den, collect(r) as rels
UNWIND rels as r
SET r.score = round((r.score-n)*100/den)/100
RETURN collect(r.score) as g, myScores