cancel
Showing results for 
Search instead for 
Did you mean: 

Count nodes with same property and return min, max and avg

pska752
Node

Hi Neo4j community,

This might be a very basic beginner question, but I cannot figure it out for the life of me after browsing trying and browsing through similar questions online.

I have got a situation like this

Now I would like to know what the minimum size / maximum size and average size of all departments is, respectively. I came across similar questions but in all cases I would 'manually' go through the different properties, however what if there were more departments, say 50 different kinds which makes it infeasable.

I basically want to do something like looping through the different departments store the occurence for each distinct department in a list and figure out the min, max and avg of that list.

I feel like this should be fairly easy but cannot figure it out.

Thank you very much for any help.

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

Try this.

match(e:Employee) 
with e.department as department, count(*) as deptSize
return min(deptSize) as minDeptSize, max(deptSize) as maxDeptSize, avg(deptSize) as avgDeptSize

View solution in original post

2 REPLIES 2

glilienfield
Ninja
Ninja

Try this.

match(e:Employee) 
with e.department as department, count(*) as deptSize
return min(deptSize) as minDeptSize, max(deptSize) as maxDeptSize, avg(deptSize) as avgDeptSize

Hi Gary,

Thank you heaps. Seems like I had the syntax slightly wrong. Appreciate the quick answer.

Best,
Philipp