I am struggling writing a query than can count users every month based on a condition where two date fields interact. First, I have a field that identifies users uniquely, a second field that registers the date when the user subscribed, and a third field that registers the date when the unsubscribes.
user, subscribed, unsubscribed
1234, 2017-01-01, null
2345, 2017-01-01, 2017-12-01
3456, 2017-03-01, 2017-05-20
The table that I would expect to see is:
date, user_count
2017-01-01, 2
2017-02-01, 2
2017-03-01, 3
2017-04-01, 3
2017-05-01, 3
2017-06-01, 2
etc...
I know that I have to include a where condition where subscribed has to be greater than unsubscribed. WHERE subscribed > unsubscribed. Null just shows that there is an empty value where the user hasn't unsubscribed. I am just not quiet sure how to count a user every time the condition is met every month of the year. Do I need to join my table to a date-month series?