2012-12-08 35 views
0

我有复杂的查询问题; 这里是我的暗号查询:neo4j中如何在密码查询中有两个聚合?

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是组名,x是各组的用户。 我如何让平均用户数量与平均用户数量进行比较? 我可以获得群组用户的平均数量,然后返回比平均用户数量多的群组吗? 谢谢。

回答

2

我不认为你可以在同一个查询中得到平均值和计数值,而无需重新启动。所以这里是我的尝试:

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 
+0

谢谢,它很有用。 – user1878364