Hello @tomas_vrba
This is a solution:
MATCH (n)
CALL {
WITH n MATCH (n)-[r]->() RETURN count(r) AS occurrences
UNION
WITH n MATCH (n)<-[r]-() RETURN count(r) AS occurrences
}
WITH n, collect(occurrences) AS values
SET n.balance = values[0] - values[1]
To speed-up this query, you can do several things if you are not working on all nodes of the database:
- specify a label or a relation type
- specify a UNIQUE CONSTRAINT and use the index created in a WHERE clause
Regards,
Cobra