I have a binary tree representation in the database:

Each node has two outgoing connections, LEFT and RIGHT.

The following query fetches the tree up to a depth of 15.

MATCH path = (d1:Distributor)-[*0..15]->(d2:Distributor)

WHERE d1.dist_id = '1'

RETURN d2, path, nodes(path) as nodes, relationships(path) as rels

Each node will also consist of a property called count, with different values.

However, what I am trying to do is. for a given node, calculate the sum of all count properties of all the child nodes in the tree below him, recursively.

I tried with the following, but evidently, it is only considering the immediate child node.

MATCH path = (d1:Distributor)-[:LEFT|RIGHT]->(d2:Distributor)

WHERE d1.dist_id = '1'

RETURN sum(d2.count)

Is there any way to achieve this?