Cypher 到 return 总节点数以及有限集合
Cypher to return total node count as well as a limited set
是否可以在单个密码查询中提取有限的节点集和节点总数?
match (n:Molecule) with n, count(*) as nb limit 10 return {N: nb, nodes: collect(n)}
以上查询正确 returns 个节点,但 returns 1 作为节点数。我当然明白为什么会这样 returns 1,因为没有分组,但不知道如何更正它。
下面的查询 returns 全部行数 的计数器(我想这是需要的)。然后它再次匹配并 限制 您的搜索,但原始计数器仍然可用,因为它是通过 WITH
语句执行的。
MATCH
(n:Molecule)
WITH
count(*) AS cnt
MATCH
(n:Molecule)
WITH
n, cnt LIMIT 10
RETURN
{ N: cnt, nodes:collect(n) } AS molecules
这是另一种解决方案:
match (n:Molecule) return {nodes: collect(n)[0..5], n: length(collect(n))}
30k 个节点需要 84 毫秒,比上面 wassgren 提出的方法更短但效率不高。
是否可以在单个密码查询中提取有限的节点集和节点总数?
match (n:Molecule) with n, count(*) as nb limit 10 return {N: nb, nodes: collect(n)}
以上查询正确 returns 个节点,但 returns 1 作为节点数。我当然明白为什么会这样 returns 1,因为没有分组,但不知道如何更正它。
下面的查询 returns 全部行数 的计数器(我想这是需要的)。然后它再次匹配并 限制 您的搜索,但原始计数器仍然可用,因为它是通过 WITH
语句执行的。
MATCH
(n:Molecule)
WITH
count(*) AS cnt
MATCH
(n:Molecule)
WITH
n, cnt LIMIT 10
RETURN
{ N: cnt, nodes:collect(n) } AS molecules
这是另一种解决方案:
match (n:Molecule) return {nodes: collect(n)[0..5], n: length(collect(n))}
30k 个节点需要 84 毫秒,比上面 wassgren 提出的方法更短但效率不高。