2013-08-20 29 views
7

Trong cơ sở dữ liệu Neo4j với một vài nút và mối quan hệ, tôi đang cố gắng tìm ra người dùng "phổ biến nhất" (trong trường hợp này: Các nút tham gia vào hầu hết các mối quan hệ):Sắp xếp các nút theo số lượng mối quan hệ -> ThisShouldNotHappenError

START n=node:user('*:*') 
MATCH (n)-[r]->(x) 
RETURN n 
ORDER BY COUNT(r) DESC 
LIMIT 10 

Tuy nhiên, truy vấn này (Neo4j 1.9.2) kết quả trong các lỗi sau:

ThisShouldNotHappenError

Developer: Andres claims that: Aggregations should not be used like this.

StackTrace: org.neo4j.cypher.internal.commands.expressions.AggregationExpression.apply(AggregationExpression.scala:31) org.neo4j.cypher.internal.commands.expressions.AggregationExpression.apply(AggregationExpression.scala:29) org.neo4j.cypher.internal.pipes.ExtractPipe$$anonfun$internalCreateResults$1$$anonfun$apply$1.apply(ExtractPipe.scala:47) org.neo4j.cypher.internal.pipes.ExtractPipe$$anonfun$internalCreateResults$1$$anonfun$apply$1.apply(ExtractPipe.scala:45) scala.collection.immutable.Map$Map1.foreach(Map.scala:109) org.neo4j.cypher.internal.pipes.ExtractPipe$$anonfun$internalCreateResults$1.apply(ExtractPipe.scala:45) org.neo4j.cypher.internal.pipes.ExtractPipe$$anonfun$internalCreateResults$1.apply(ExtractPipe.scala:44) scala.collection.Iterator$$anon$11.next(Iterator.scala:328) org.neo4j.cypher.internal.pipes.TopPipe.internalCreateResults(TopPipe.scala:45) org.neo4j.cypher.internal.pipes.PipeWithSource.createResults(Pipe.scala:69) org.neo4j.cypher.internal.pipes.PipeWithSource.createResults(Pipe.scala:66) org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl.org$neo4j$cypher$internal$executionplan$ExecutionPlanImpl$$prepareStateAndResult(ExecutionPlanImpl.scala:164) org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$getLazyReadonlyQuery$1.apply(ExecutionPlanImpl.scala:139) org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$getLazyReadonlyQuery$1.apply(ExecutionPlanImpl.scala:138) org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl.execute(ExecutionPlanImpl.scala:38) org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:72) org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:76) org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79) org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:94) java.lang.reflect.Method.invoke(Method.java:611) org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)

Bất kỳ ý tưởng về làm thế nào tôi có thể bày tỏ này differntly?

Trả lời

15

Về neo4j mannual, nếu bạn cần phải sử dụng một aggregration trong bạn "Sắp xếp theo", bạn phải bao gồm aggregration trong "Return", vì vậy bạn chỉ cần thêm số (r) vào "Trả lại" của bạn như được hiển thị bên dưới,

START n=node:user('*:*') 
MATCH (n)-[r]->(x) 
RETURN n, COUNT(r) 
ORDER BY COUNT(r) DESC 
LIMIT 10 
4

giới thiệu một WITH đây:

START n=node:user('*:*') 
MATCH (n)-[r]->() 
WITH n, count(r) as c 
RETURN n, c 
ORDER BY c DESC 
LIMIT 10 
+3

+1 Bạn thực sự có thể thêm nó vào trả về: 'return n, count (r) là c order by c', 'WITH' là không cần thiết. –

Các vấn đề liên quan