This code works perfectly, SELECT distinct Customer_Number, SUM(Price) As TotalFROM Customer_Offer x1WHERE EXISTS (SELECT * FROM Customer_Offer x2 WHERE x2.Customer_Number = x1.Customer_Number AND x2.Product_Offer = 'prod1') AND NOT EXISTS (SELECT * FROM Customer_Offer x3 WHERE x3.Customer_Number = x1.Customer_Number AND x3.Product_Offer IN ( 'prod2','prod3', 'prod4') ) GROUP BY Customer_Number ORDER BY Customer_Number;
however I would like to find customers who have bought prod1 and prod2 and not bought prod3 and prod4, I tried using this codeSELECT distinct Customer_Number, SUM(price) As TotalFROM Customer_Offer x1WHERE EXISTS (SELECT * FROM Customer_Offer x2 WHERE x2.customer_number = x1.customer_number AND x2.product_offer IN ('prod1', prod2) AND NOT EXISTS (SELECT * FROM Customer_Offer x3 WHERE x3.customer_number = x1.customer_number AND x3.product_offer IN ( 'prod3','prod4') )GROUP BY Customer_numberORDER BY Customer_Number; but get a syntax error! is anyone able to point me in the right direction for what I am trying to achieve?