The relationship between the nodes are: (a)--[:PARTOF]-->(t)<--[:PARTOF]--(s)
I am trying to find the sum of all ages in Team1. I used this query below however, it gives me a sum total that is incorrect. The sum total of the age should be 242 but i keep getting 852. Is there something I am doing wrong?
// MATCH (a:Accountant)-[:PARTOF]->(:Team1)<-[:PARTOF]-(s:Salesperson)
RETURN sum(a.age)+sum(s.age) AS Total //
@elena.kohlwey thanks for the response. I've been reading up on clause section of neo4j manual bits and pieces of information here and there. Your explanation helped me clear up some misunderstandings I had about path of travel.
Regarding the solution with the WITH clause provided, I just want to make sure I have the correct concept in understanding how the WITH clause actually works. (I ran it using an EXPLAIN in the beginning to see the path) What I am seeing is that we are aggregating in this case the sum of all accountant ages and passing it to the alias variable "accountantAge" which from my understanding must always follow a WITH statement in order to pass the value. After that, we are passing the variable 't' of Team1 in order for the next MATCH statement to use. Did I get it correct?
@clem haha thx. For being a beginner, I just create random data in order to test if I understand the concepts. but i'll try out that scenario.
Yes, I think you got it. The use of the variable t goes into the direction of what @clem said. If you have several teams (Team1 nodes in your case), you would want to get the overall age of one specific team or of several ones separately. The "WITH t" makes sure that in the third line you only look for all nodes that are connected to the same node that you had in your first line.