2012-12-08 5 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

관련 문제