Showing results for 
Search instead for 
Did you mean: 

How to obtain list of degrees of nodes


I have a graph and I would like to obtain the list of degrees (across the nodes). The following statement does the trick : 


match (n:PROF)-[r]-() with n, count(r) as degree return degree
There's however, something I don't get in the logic. When I write this statement :
match (n:PROF)-[r]-() with count(r) as degree return degree
or this one
match (n:PROF)-[r]-() return count(r) as degree
I get the sum of the counts across the nodes, not the counts as a list. 
I also realised that this statement 

match (n:PROF)-[r]-() return n, count(r) as degree
also returns each degree. But it also has the nodes in the returned table...
So it seems that the fact that "n" is return (or passed further with "with") changes the format of the response. Is there somewhere a document that explains this logic ?
So it seems that I have to return the nodes (with n)


the use of an aggregate function, such as count, causes the data to be grouped by the other items returned. These are called grouping keys. The aggregation we be applied over each unique combination of those parameters.  This is true for aggregate functions on both ‘return’ and ‘with’ clauses.  This is very similar to a SQL ‘group by’ clause.

Graph Maven

Try this: This shows all the relationships associated with node 'PROF'. Also shows count of each relationship type.

match (n:PROF)-[r]-()

with distinct type(r) as rel, count(distinct type(r)) as cnt
with collect(rel) as rels, collect(cnt) as cnts
return rels, cnts

Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.