在一个cypher查询中,是否有可能提取有限的节点集和节点总数?
match (n:Molecule) with n, count(*) as nb limit 10 return {N: nb, nodes: collect(n)}
上述查询正确返回了节点,但将节点数作为1返回。我当然知道为什么会返回1,因为没有分组,但是不知道如何进行更正。
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))}
30,000个节点,84毫秒。这比由Wassgren提出的上述方法更短,但不如效率高。
collect
语句吗? - canbaxOPTIONAL MATCH (x:Card) WHERE ( (TRUE) ) RETURN ID(x), x SKIP 0 LIMIT 10
的查询来从这290万张卡片中获取10张卡片。它的执行时间只有1到2毫秒。但是当我尝试使用 OPTIONAL MATCH (x:Card) WHERE ( (TRUE) ) RETURN collect(ID(x))[0..10], collect(x)[0..10], length(collect(x))
时,第一次执行需要4500毫秒。在第二次运行时,它执行了2700毫秒。虽然看起来不太糟糕,但肯定比前者慢。 - canbaxMATCH (n:MyLabel)
WITH collect(n) as collection,count(n) as cnt
CALL{
WITH collection
UNWIND collection as item
WITH item ORDER BY item.id DESC SKIP 10 LIMIT 5
RETURN collect(item) as items
}
RETURN cnt, items
where
语句结合起来?基本上,我不想要总节点数。我想要满足“某些”条件的节点计数。 - canbax