cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Filter based on sum of array relationship property

flpgrz
Node Link

Hello,

In my graph, relationships have a property named list. list is an array of int.

It looks like this:
(head:Node)-[r:RELATIONSHIP {list:...}]->(tail:Node)

I'd like to query all tails in the graph, where the sum of list is > 0.

Intuitively, I would do:

MATCH (:Node)-[r:RELATIONSHIP]->(tail:Node)
WHERE sum(r.list) > 0
RETURN tail

This does not work unfortunately. It throws an error. How can I write this query?
Thanks

1 ACCEPTED SOLUTION

MATCH (head:Node)
CALL {
WITH head
MATCH (head)-[r:RELATIONSHIP]->(tail:Node)
WHERE apoc.coll.sum(r.list) > 0
RETURN tail
}
RETURN tail

View solution in original post

2 REPLIES 2

MATCH (head:Node)
CALL {
WITH head
MATCH (head)-[r:RELATIONSHIP]->(tail:Node)
WHERE apoc.coll.sum(r.list) > 0
RETURN tail
}
RETURN tail

Newbie question:

Is there an explanation of what's wrong with the original solution and why you need an apoc call to solve the problem? (I'm also curious as to what the error was. If I get around to trying this out, I'll post the errmsg.)

I'm not sure why apoc calls are needed here. I get the feeling this is a bit similar to SQL in Spark with UDF's, but my intuition on all this isn't well developed yet.

Thanks.