Suppose to have the following DB:
create (a:fooNode{name:'A'}),(b:fooNode{name:'B'}),(c:fooNode{name:'C'}),(d:fooNode{name:'D'}),(e:fooNode{name:'E'}),(p1:pNode{name:'p1'}),(p2:pNode{name:'p2'}),(a)-[e1:Edge{w:10}]->(p1),(b)-[e2:Edge{w:30}]->(p1),(c)-[e3:Edge{w:25}]->(p1),(d)-[e4:Edge{w:15}]->(p2),(e)-[e5:Edge{w:20}]->(p2), (source:fooNode{name:'Node 0'}), (source)-[:Edge]->(a), (source)-[:Edge]->(b), (source)-[:Edge]->(c), (source)-[:Edge]->(d), (source)-[:Edge]->(e)
This image should clarify the idea.
Now I'm interested in having as result the sum of the incoming nodes' weight per 'pNode'. Something like:[ p1: 65, p2: 35]
Please notice that I cannot know the names of the nodes in advance, except for the source node, called 'Node 0' in the example DB. Firstly, i thought about computing the path from 'Node 0' to whichever 'pNode', but I don't know how to procede further.
To get the sum of incoming weights for all pNodes
:
MATCH ()-[e]->(n:pNode)
RETURN n.name, sum(e.w) as weight
and for a specific pNode
:
MATCH ()-[e]->(n:pNode)
WHERE n.name = "p1"
RETURN n.name, sum(e.w) as weight