this will give the degree,indegree and outdegree of all nodes .... indegree=0 is your root
(code thanks to wes/michael some days ago in one of my posts)
match (n)-[r]-()
with n, sum(case when startnode(r) = n then 1 else 0 end) as outdegree, sum(case when endnode(r) = n then 1 else 0 end) as indegree
return id(n),n.nodename as nodename, outdegree, indegree, outdegree+indegree AS degree
order by indegree asc
this only indegree 0
match (n)-[r]-()
with n, sum(case when endnode(r) = n then 1 else 0 end) as
indegree where indegree=0
return id(n),n.nodename as nodename, indegree
order by indegree asc
reg koen