简体   繁体   中英

Neo4j cypher avoid negative values

I have a node that has properties based on another node, For example:

MATCH (n:draft {sn:1}),(m:final {sn:1})
SET m.count = m.count - n.count
RETURN m

Seems to work. However what I want to do is set m.count to 0 if n.count > m.count . n.count > m.count results in a negative value and I want to avoid this.

You should be able to do this:

MATCH (n:draft {sn:1}),(m:final {sn:1})
SET m.count = CASE WHEN n.count > m.count THEN 0 ELSE m.count - n.count END 
RETURN m

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM