cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Count nodes by property value

hafeja
Node Link

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?

1 ACCEPTED SOLUTION

Hello @hafeja and welcome to the Neo4j community

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

Regards,
Cobra

View solution in original post

2 REPLIES 2

Hello @hafeja and welcome to the Neo4j community

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

Regards,
Cobra

Wow! Thank you for the super fast reply!