Cypher: loop over properties and count

cypher, neo4j

Solution

This very simple query will return a count of every distinct `gender` value. You can do the same thing for any property with any number of possible values.

MATCH (n)
RETURN n.gender, COUNT(*)

You should modify the `MATCH` clause to specifically pick nodes that actually have the property you are counting. (Any matched nodes that do not have that property would also be counted, with a value of `null` -- and appear in the results.)

Problem

I have a lot of nodes, containing the property `gender`. Possible values for `gender` are: male, female and andy. I am looking for a cypher query, that will return the count of each value. For example... ``` "male" 100 "female" 132 "andy" 12 ``` The solution should also work for nodes with a property with more than three cases, eg. names, and the number of persons with the name.

Original source