cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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:

tie219_0-1655307960636.png

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!

1 REPLY 1

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?