how to have two aggregation in cypher query in neo4j?

人走茶凉 提交于 2019-12-23 05:05:04

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/13781934/how-to-have-two-aggregation-in-cypher-query-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!