Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Expect disruption to service on Thursday, Feb. 9!

Return Start and End Nodes in a path while using reduce function


Hi all, just getting started with neo4j and am querying a database that one of my colleagues created for an alternate purpose.

Here's a visualization of what I'm attempting to accomplish:


In my network, I have the following nodes and relationships above, where we have input_skus, output_skus and GOES_INTO and TRANSFER_TO relationships between materials and plants. I would like to return the orange circles (raw materials) with their weight percents of the blue circle (fg). I was able to retrieve the orange circles when I include a where clause that filters for the FG (blue circle) specifically. However, my network has tens of thousands of blue circles in it and I need a way of retrieving all of them. In the end, I would like 5 columns as a result of my query: From_Plant, From_Material, To_Plant, To_Material, Weight. Where the intermediate steps are reduced down. 

Here's my current query which isn't quite working: 

MATCH p=(sku_input:SKU)-[:GOES_INTO|TRANSFERS_TO*0..30]->(sku_middle:SKU)-[r:GOES_INTO|TRANSFERS_TO]->(sku_output:SKU)
WHERE  NOT (:SKU)-[:GOES_INTO]->(sku_input) 
   and NOT (sku_output)-[:GOES_INTO|TRANSFERS_TO]->(:SKU) 
RETURN sku_input.ID,sku_output.ID,[IN relationships(p)| type(r)],  reduce(res = 1.00, r IN relationships(p) | res*tofloat(r.WGHT))

Any help would be appreciated, thank you!



Are you looking for paths between the yellow nodes and the blue nodes?  If so, do the yellow and blue nodes have specific labels or identifiers to match on instead of testing for the no incoming or outgoing relationships? 

What is wrong with your query and what are you looking to achieve?