I have got two arrays through the following cypher query
return p.home,p1.away
collect(distinct toInteger(p.score[0])) as value1,
collect(distinct toInteger(p1.score[1])) as value2
Here, value1=[1,2,3,4] and value=[3,0,6,2] I wanted to have:
sum (1+2+3+4+3+0+6+2) as totalValue ?
Is
distinct
a necessity? If it isn't, you can simply use:If you have to use
distinct
first, you can sum elements in arrays like this:This uses the
range
function to define a variablei
that iterates on the arrays.Note that
value1
andvalue2
are not the best names: arrays should have a plural name (e.g.values1
).