问题
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