Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-05-2020 05:54 AM
Hi Guys
I am having property nodes of student like
{studentId:"1", English:20}
{studentId:"1", Maths:20}
{studentId:"1", physics:20}
I need to have final node like
{studentId:"1",total:60}
Is it possible using Trigger?
Can anyone help on this situation??
10-05-2020 09:17 AM
create nodes
MERGE (s:Student {studentId: "1",name:"1"})
MERGE (math:Subject:Math {marks: 20})
MERGE (eng:Subject:English {marks: 20})
MERGE (physics:Subject:Physics {marks: 20})
MERGE (s)-[:HAS_SUBJECT]->(math)
MERGE (s)-[:HAS_SUBJECT]->(eng)
MERGE (s)-[:HAS_SUBJECT]->(physics)
and run aggregate query
MATCH (s:Student)-[r:HAS_SUBJECT]->(sub:Subject)
WITH s, sum(sub.marks) as total
MERGE (s)-[:TOTAL_MARKS]->(t:Total {marks:total})
RETURN *;
You can use trigger as well:
call apoc.trigger.add("total","MATCH (s:Student)-[r:HAS_SUBJECT]->(sub:Subject)
WITH s, sum(sub.marks) as total
MERGE (s)-[:TOTAL_MARKS]->(t:Total {marks:total})",{phase:'before'});
All the sessions of the conference are now available online