Search code examples
sumcypher

How to sum two numbers in Cypher?


Given two numeric properties n.in and n.out, how can I get the sum of them?

My query

match (n) 
return n.name, id(n), sum(n.in,n.out);

But obviously this is false since SUM is for only one property. Looking at Numeric mathematical functions there is no such function too.


Solution

  • Like this?

    match(n)
    with sum(n.in + n.out) as sumOfAllNodes
    match(n)
    return n.name, id(n), n.in + n.out as sumOfaNode, sumOfAllNodes