Neo4j aggregate function

2019-02-28 01:31发布

I am trying to use the SUM function and store the result of it as a new property of the relationship. But it is not working. The query I used is :

MATCH (a:Employee)-[r:CorporateMessage]->(b)
WHERE a.Eid = 6001 AND b.Eid IN [6002,6003,6004,6005,5001]
SET r.Internalsum = SUM(r.Count)

The error i got was:

Invalid use of aggregating function sum(...) in this context (line 1, column 124 (offset: 123)) "MATCH (a:Employee)-[r:CorporateMessage]->(b)WHERE a.Eid = 6001 AND b.Eid IN [6002,6003,6004,6005,5001] SET r.Internalsum = SUM(r.Count)"

Kindly explain what i am doing wrong.

标签: neo4j cypher
1条回答
看我几分像从前
2楼-- · 2019-02-28 01:46

Try it:

MATCH (a:Employee)-[r:CorporateMessage]->(b)
WHERE a.Eid = 6001 AND b.Eid IN [6002,6003,6004,6005,5001]
WITH r, SUM(r.count) as count
SET r.Internalsum = count

Always put aggregation functions in WITH or RETURN.

查看更多
登录 后发表回答