Count nodes by property value

Hello,

I need some help to create a cypher query.

For all different values of property "job", the query shall return the property name and the amount of nodes that have this property value.

Sample data:

CREATE (:Person {age: 20, job: "SW engineer"})
CREATE (:Person {age: 21, job: "HW engineer"})
CREATE (:Person {age: 22, job: "SW engineer"})
CREATE (:Person {age: 40, job: "boss"})
CREATE (:Person {age: 40, job: "architect"})
CREATE (:Person {age: 99, job: "boss"})
CREATE (:Person {age: 30, job: "boss"})

Expected output:

Job            | count
____________________________
SW engineer    | 2
HW engineer    | 1
boss           | 3
architect      | 1

Any ideas?

Hello @hafeja and welcome to the Neo4j community :slight_smile:

MATCH (p:Person)
RETURN p.job AS job, count(p.job) AS count

Regards,
Cobra

:+1: Wow! Thank you for the super fast reply!

1 Like