Ram
Ram

Reputation: 97

Neo4j aggregate function

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.

Upvotes: 1

Views: 932

Answers (1)

Bruno Peres
Bruno Peres

Reputation: 16355

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.

Upvotes: 3

Related Questions