Ok, I'm trying to get a count of users who bought something in a given month but haven't bought something already in any of the previous months (as in, figure out how many new users are there each month), so this is what I'm kinda trying to do but it's obviously not working:
SELECT COUNT(DISTINCT user_id NOT IN (
SELECT user_id
FROM payment
WHERE amount > 0
AND MONTH(payment_date) < "10"
GROUP BY user_id
) AS new_users_count
FROM payment
WHERE amount > 0
AND MONTH(payment_date) >= "10"
If I use "DISTINCT" it returns 0 count.
If I take it out, it returns all the users, new and old.
Plus having a subquery in COUNT() takes a while to process.
Any way this can be done with SUM(IF...)? Or any other more optimal way?
I've looked everywhere for an idea/solution, just can't figure it out.