I have a dataset where each observation represents monthly sales per customer. A customer can have multiple months with positive sales and some months with negative sales. I want to remove all customers with at least one month of negative sales. I’ve tried these two examples, but I still have customers with negative sales. What could be the issue?
Example 1:
SELECT *
FROM table_A a
WHERE a.customer NOT IN (
SELECT customer
FROM table_A sub_a
WHERE sub_a.sales < 0
)
ORDER BY sales;
Example 2:
SELECT a.*
FROM table_A a
WHERE NOT EXISTS (
SELECT 1
FROM table_A sub_a
WHERE sub_a.customer = a.customer
AND sub_a.sales < 0
)
ORDER BY a.sales;
Any suggestions?