The second query gives a list of customerkeys. I want that result to be used on the fist query as long as I only want to match the customers with the keys that are on that list. In SQL there is a IN operator. What about in Cypher?
MATCH (s:Sale)-[:ORDERED_BY]->(c:Customer)
WHERE c.customerKey IN ******
RETURN c.name, SUM(s.orderQuantity)
MATCH (s:Sale)-[:CUSTOMER]->(c:Customer)
WITH SUM(s.orderQuantity) as qtt, c
WHERE qtt>1
RETURN c.customerKey
There is an IN operator that works on lists, and there is a COLLECT() command that changes rows into a list.
That said, I don't think you need to do this step at all. You should be able to combine the two queries and just use the customers resulting from the second query to feed into the first query like so:
MATCH (s:Sale)-[:CUSTOMER]->(c:Customer)
WITH SUM(s.orderQuantity) as qtt, c
WHERE qtt>1
// now pass the filtered list of customers to the first query
// no need to do any additional filtering or even deal with customerKey
WITH c
MATCH (s:Sale)-[:ORDERED_BY]->(c)
RETURN c.name, SUM(s.orderQuantity)