返回总节点数和有限集的Cypher [英] Cypher to return total node count as well as a limited set

查看:55
本文介绍了返回总节点数和有限集的Cypher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在单个密码查询中提取有限的节点集和节点总数?

Is it possible to extract in a single cypher query a limited set of nodes and the total number of nodes?

match (n:Molecule) with n, count(*) as nb limit 10 return {N: nb, nodes: collect(n)}

上面的查询正确返回了节点,但是返回1作为节点数.我当然理解为什么它返回1,因为没有分组,但无法弄清楚如何纠正它.

The above query properly returns the nodes, but returns 1 as number of nodes. I certainly understand why it returns 1, since there is no grouping, but can't figure out how to correct it.

推荐答案

以下查询返回整个行数的计数器(我想这是必需的).然后,它再次匹配并限制 您的搜索,但是原始计数器仍然可用,因为它是通过WITH语句进行传递的.

The following query returns the counter for the entire number of rows (which I guess is what was needed). Then it matches again and limits your search, but the original counter is still available since it is carried through via the WITH-statement.

MATCH 
    (n:Molecule)
WITH 
    count(*) AS cnt
MATCH 
    (n:Molecule)
WITH 
    n, cnt LIMIT 10
RETURN 
    { N: cnt, nodes:collect(n) } AS molecules

这篇关于返回总节点数和有限集的Cypher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆