我想总结一下neo4j集合的每个值,任何人都可以告诉我这个cypher这个我有三个集合已经MEASURES1,MEASURES2,MEASURES3
请参阅下面的图片附件,以便非常清楚地查看问题
Image for this question see this to get more clear idea about the question
答案 0 :(得分:0)
我得到了答案:
返回
减少(s = 0,x IN MEASURES1 | s + x)AS MEASURES1,
reduce(s = 0,x IN MEASURES2 | s + x)AS MEASURES2,
reduce(s = 0,x IN MEASURES3 | s + x)AS MEASURES3
reduce()功能将按照我们的要求运行:)
答案 1 :(得分:0)
您可以使用reduce()功能来实现目标。看看:
WITH [14,1] AS MEASURES1, [] AS MEASURES2, [1,1,1,1,1,1,2,1,1,1,1,1] AS MEASURES3
WITH reduce(acc1 = 0, v1 in MEASURES1 | acc1 + v1) AS MEASURES1,
reduce(acc2 = 0, v2 in MEASURES2 | acc2 + v2) AS MEASURES2,
reduce(acc3 = 0, v3 in MEASURES3 | acc3 + v3) AS MEASURES3
RETURN MEASURES1, MEASURES2, MEASURES3
以上查询的结果:
+-----------------------------------+
| MEASURES1 | MEASURES2 | MEASURES3 |
+-----------------------------------+
| 15 | 0 | 13 |
+-----------------------------------+
答案 2 :(得分:0)
如果您有权访问APOC Procedures,则可以使用对集合进行操作的辅助函数,包括apoc.coll.sum()
,它可以完全满足您的需求:
...
RETURN apoc.coll.sum(MEASURES1) as m1Sum, apoc.coll.sum(MEASURES2) as m2Sum, apoc.coll.sum(MEASURES3) as m3Sum