neo4j 怎样实现分组查询
发布于 5 天前 作者 dlliwei 60 次浏览 来自 问答

请问,谁知道:neo4j 怎样实现分组查询,每组返回前10个?

5 回复
根据不同的条件查询 并返回么?

这种么

with [1,2,3,4,5,6] as list
unwind list as li
call apoc.case(
[li=1 or li=2,"MATCH (n:Partner) RETURN n LIMIT 10"
,li=3,"MATCH (n:Name) RETURN n LIMIT 10"]
,"MATCH (n:ShareHolder) RETURN n LIMIT 10",null) yield value
return value

neo4j好像没有分组概念,A字段不做处理,其他字段处理了,自动就按A字段分组

可以先压到排序的集合/列表里,然后取前N个: MATCH … … WITH group1, group2, collect(data1)[0…9] AS col1, collect(data2)[0…9] AS col2 ORDER BY group1, group2 WITH group1, group2, col1, col2, range(0,9) AS iterator UNWIND iterator AS i RETURH group1, group2, col1[i], col2[i]

@graphway 你说的的很对, 我用collect 返回分组数据如下(每个from,返回5个数据): match (from)-[r]->(to) where from.id in [1,2,3] WITH from,r,to ORDER BY r.age DESC WITH from, collect( r )[0…5] AS rel RETURN from, rel

回到顶部