Count active users based on logins last 90 days
<p>I am trying to make a query that will result in a list showing how many active users we have month by month. We define an active users as a user that have been logged in in the last 90 days.</p>

<p>I can easily define the number of active users we have right now by this</p>

<pre><code>SELECT COUNT(DISTINCT(user_id) FROM login_table
WHERE login_date BETWEEN DATE_SUB(login_date, INTERVAL 90 DAY) AND NOW())
</code></pre>

<p>My problem comes when I have to count the amount of users we have month by month
Here i have to count one single login several times. </p>

<p>If I have a user that login at 10 of January, and never login again, this user should count as an active user in the following months: January, February, March and April, even though I only have one registration of the user</p>

<p>Example data:</p>

<pre><code>login_date | user_id
2015-01-01 | 1
2015-02-10 | 1
2015-02-11 | 2
2015-02-13 | 1
2015-03-19 | 1
</code></pre>

<p>This should result in something like this: </p>

<pre><code>Date    | Active users
2015-01 | 1 
2015-02 | 2
2015-03 | 2 
2015-04 | 2 
2015-05 | 2 
2015-06 | 1 
2015-07 | 0 
2015-08 | 0 
</code></pre>

<p>Is there anyway of doing a count like that? </p>