Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-10-2022 03:52 PM - edited 06-10-2022 03:55 PM
Hi Neo Friends!
The query below is a modified version of a query I made that works when I am searching in the CONTAINS clause for only a single product type, but I've tried multiple ways of searching for more than one, such as making a list with commas, or using the OR operator, but I can't get it to work. Any advise?
Cypher that is having issues:
Works when I do this:
Solved! Go to Solution.
06-10-2022 04:03 PM - edited 06-10-2022 04:04 PM
Try the following, it uses the list predicate 'any' to achieve what you want:
WITH ["SuperU", "UAN", "Urea"] as types
MATCH (type:ProductType)
WHERE any (i in types where i = type.name )
MATCH (type)<-[:HAS_PRODUCT_TYPE]-(:Product)<-[:HAS_PRODUCT]-(:ProductOrigin)<-[:HAS_PRODUCT_ORIGIN]-(c:OrderLine)-[hq:HAS_QUANTITY]->(Q:Quantity)
RETURN type.name AS ProductType, Q.quantity AS Quantity
It would seem that you may have multiple paths for each product name, so do you want to sum the quantity per product name.
WITH ["SuperU", "UAN", "Urea"] as types
MATCH (type:ProductType)
WHERE any (i in types where i = type.name )
MATCH (type)<-[:HAS_PRODUCT_TYPE]-(:Product)<-[:HAS_PRODUCT]-(:ProductOrigin)<-[:HAS_PRODUCT_ORIGIN]-(c:OrderLine)-[hq:HAS_QUANTITY]->(Q:Quantity)
RETURN type.name AS ProductType, sum(Q.quantity) AS TotalQuantity
06-10-2022 04:03 PM - edited 06-10-2022 04:04 PM
Try the following, it uses the list predicate 'any' to achieve what you want:
WITH ["SuperU", "UAN", "Urea"] as types
MATCH (type:ProductType)
WHERE any (i in types where i = type.name )
MATCH (type)<-[:HAS_PRODUCT_TYPE]-(:Product)<-[:HAS_PRODUCT]-(:ProductOrigin)<-[:HAS_PRODUCT_ORIGIN]-(c:OrderLine)-[hq:HAS_QUANTITY]->(Q:Quantity)
RETURN type.name AS ProductType, Q.quantity AS Quantity
It would seem that you may have multiple paths for each product name, so do you want to sum the quantity per product name.
WITH ["SuperU", "UAN", "Urea"] as types
MATCH (type:ProductType)
WHERE any (i in types where i = type.name )
MATCH (type)<-[:HAS_PRODUCT_TYPE]-(:Product)<-[:HAS_PRODUCT]-(:ProductOrigin)<-[:HAS_PRODUCT_ORIGIN]-(c:OrderLine)-[hq:HAS_QUANTITY]->(Q:Quantity)
RETURN type.name AS ProductType, sum(Q.quantity) AS TotalQuantity
06-10-2022 10:58 PM
Try this:
WHERE type.name CONTAINS ("SuperU") OR type.name CONTAINS ("UAN") OR type.name CONTAINS ("Urea")
All the sessions of the conference are now available online