Well on 1.9 you may need a with:

START c=node(*)
WHERE HAS (c.A) AND HAS (c.B)
WITH collect(c) AS allC
with reduce(total = 0, x IN allC| total + abs(x.A - x.B)) AS sum
return sum




On Fri, Jul 18, 2014 at 10:09 PM, Luanne Coutinho <[email protected]
> wrote:

> Hi,
>
> Which version are you using?
>
> If you're on 2.0 then this should work:
>
> MATCH c
> WHERE HAS (c.A) AND HAS (c.B)
> WITH collect(c) AS allC
> RETURN reduce(total = 0, x IN allC| total + abs(x.A - x.B)) AS sum
>
> and if on 1.9 then
> START c=node(*)
> WHERE HAS (c.A) AND HAS (c.B)
> WITH collect(c) AS allC
> RETURN reduce(total = 0, x IN allC| total + abs(x.A - x.B)) AS sum
>
> These will return one row with the sum in them. Hope that's what you're
> looking for. If you assign  a path
> START c=node(*)
> WHERE HAS (c.A) AND HAS (c.B)
> WITH collect(c) AS allC
> RETURN reduce(total = 0, x IN allC| total + abs(x.A - x.B)) AS sum
>
> then you're going to get back as many rows as there are paths which in
> your case is the number of nodes with both A and B properties on them- and
> the sum for each node.
>
> Regards
> Luanne
>
>
>
> On Fri, Jul 18, 2014 at 8:30 PM, <[email protected]> wrote:
>
>> Hello,
>>
>> I'm trying to use the CYPHER Reduce statement on the following:
>>
>> Some nodes in the graph have properties: .A and .B which are numeric.
>>  For every node that has these properties, I want to take the absolute
>> value of the difference between the two and sum across all nodes.  I've
>> tried the following:
>>
>> start
>> c=node(*) match p=(c) where has(c.A) and has(.B) return reduce(total = 0, x 
>> in nodes(p)| total + abs(x.A
>> - x.B)) as sum;
>>
>> But I get an error: "Don't know how to Subtract(Property..."
>>
>> Are the math operations something I'll have to do in a separate step?
>>
>> Thanks.
>>
>> -Patrick
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Neo4j" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to