how to have two aggregation in cypher query in neo

2019-06-08 20:49发布

i have problem with complex queries; here is my cypher query:

params.put("query", "name:*");
ExecutionResult result = engine.execute( "start n=node:groups({query}) 
match n<-[:Members_In]-x 
with n,count(distinct x) as numberOfUsers
where numOfUsers>avg(numOfUsers) 
return  n.name,numOfUsers ", params );

n is the group name and x is the users of each group. how can i have avg of group users count and compare it with each group users count? can I get the average number of group users and then return the groups with more users than avg? Thanks.

标签: neo4j cypher
1条回答
爷、活的狠高调
2楼-- · 2019-06-08 21:43

I don't think you can get the avg and the counts in the same query, without restarting. So here's my attempt:

start n=node:groups({query}) 
match n<-[:Members_In]-x 
with n, count(distinct x) as cnt
with avg(cnt) as av
start n=node:groups({query}) 
match n<-[:Members_In]-x
with n, av, count(distinct x) as numOfUsers
where numOfUsers > av
return n.name, numOfUsers, av
查看更多
登录 后发表回答