neo4jcypher

NEO4j Cypher : How to set a value to the Max of 2 other values


I need to retrospectively set a relationship property to the MAX of a value from the 2 nodes connected by it.

This sudo code is what im trying to do..

MATCH (a)-[r:Follows]->(b) SET r.prop = MAX(a.prop, b.prop)

But MAX doesn't work like that, its for finding the max from a collection.

Any ideas how to do this?


Solution

  • This is probably easiest with CASE.

    MATCH (a)-[r:Follows]->(b)
    SET r.prop = CASE WHEN a.prop > b.prop THEN a.prop ELSE b.prop END;