如何在Neo4J中使用WITH传递COUNT

时间:2017-05-04 11:19:56

标签: neo4j cypher

我有以下密码查询 -

MATCH(from: GContact)
WHERE NOT from:migrationComplete
WITH from
LIMIT 10
SET from:migrationComplete
WITH from, COUNT(from) AS booleanCount
MATCH (from)-[r:has]->(to: GEmail)
WITH from, to, booleanCount
MERGE (from)-[r:contactHasEmail]->(to)
RETURN booleanCount

我希望查询返回from之后找到的SET的数量,即<=10

但是,查询返回MATCH (from)-[r:has]->(to: GEmail)中找到的匹配数。有没有办法将原始计数一直传递并返回?

1 个答案:

答案 0 :(得分:0)

您不能将聚合和未聚合的值作为一般事实返回。

但您可以使用collect:

再次聚合和分发
MATCH(from: GContact)
WHERE NOT from:migrationComplete
WITH from
LIMIT 10
SET from:migrationComplete
WITH COLLECT(from) AS nodes
UNWIND nodes as from
WITH from, size(nodes) AS booleanCount
MATCH (from)-[r:has]->(to: GEmail)
WITH from, to, booleanCount
MERGE (from)-[r:contactHasEmail]->(to)
RETURN booleanCount

您也可以在最后使用RETURN count(distinct from) as booleanCount