We have users, groups and a third thing (measurements) in our database.
User can be members of one or more groups.
(g1:Group) / (User) - (Measurement) \ (g2:Group)
Now I need to do something with the Measurement, dependent on the number of groups of which the user is member of.
How can I count the number of relationships of users per row? All my tries failed so far and do a database wide aggregation of these relations.
The situation is a bit more complicated, because users usually have two relationships/edges to the groups.
(Group) / \ |[:a] |[:b] \ / (User)
My Code so far:
MATCH (u:User)-[mRel:IS_MEMBER]->(hh:Household) RETURN COUNT(DISTINCT mRel) AS groups; // gives +--------+ | groups | +--------+ | 13 | +--------+ // CASE COUNT(mRel) WHEN 1 THEN 1 ELSE COUNT(mRel) END as result
UNWIND on collected users does not help, using paths does not help, too, because two groups are of cause not part of the same path.
MATCH (u:User) WITH ID(u) AS userId MATCH (user:User)-[r:IS_MEMBER]->(h:Household) WHERE ID(user) = userId RETURN COUNT(r) as groups
gives the same result.
So COUNT seems to be the wrong approach, but I cannot see an alternative for counting relationships of nodes in a row yet.