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.

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)
2 REPLIES 2

glilienfield
Ninja
Ninja

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. 

https://neo4j.com/docs/cypher-manual/current/functions/aggregating/

ameyasoft
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