I'm trying to find the clients, those who didn't order in the last 2 years and they ordered this year more than 500.. I wrote this query and I used the "NOT EXISTS" condition, but it is still showing me the wrong results. Some suggestions would be appreciated.
My code:
SELECT "Sales"."Kundennummer" as 'Neuer Kunde', year("Sales"."Datum"), sum("Sales"."Umsatz mit Steuer") as "Umsatz" FROM "Sales" WHERE year("Sales"."Datum") = '2017' AND NOT EXISTS ( SELECT "Sales"."Kundennummer" FROM "Sales" WHERE year("Sales"."Datum") = '2015' AND year("Sales"."Datum") = '2016' ) GROUP BY "Sales"."Kundennummer", "Sales"."Datum" HAVING sum("Sales"."Umsatz mit Steuer") > 500
ORinstead ofANDwhen comparing with 2015 and 2016. The year can't be 2015 and 2016 at the same time