title: Count of Distinct users based on dynamic dates
body: <p>I have a table that records the date each time a user logs in to my application.</p>
  
  <p>the table looks like this:</p>
  
  <pre><code>Userid: int
  logintime: timestamp
  </code></pre>
  
  <p>the data looks like this:</p>
  
  <pre><code>Userid   logindate
  2        2013-09-01
  2        2013-09-02
  3        2013-09-02
  4        2013-09-02
  4        2013-09-03
  5        2013-09-03
  </code></pre>
  
  <p>I want to find the number of distinct users that are new every day while keeping track of old users so the results I want looks like this:</p>
  
  <pre><code>logindate   count of users
  2013-09-01  1
  2013-09-02  3 
  2013-09-03  4
  </code></pre>
  
  <p>On 2013-09-01 I need to count distinct on this day
  On 2013-09-02 I need to count distinct between 2013-09-01 and 2013-09-02
  On 2013-09-03 I need to count distinct between 2013-09-01 and 2013-09-03</p>
  
  <p>I thought of something like the below but it never returns (takes alot of time)</p>
  
  <pre><code>select date(ul.logintime) d, 
  (select count(distinct ul2.userid) from userlogin ul2 where 
  date(ul2.logintime) between ADDDATE(LAST_DAY(SUBDATE(curdate(), INTERVAL 1 MONTH)), 1) 
  and date(ul.logintime)) dis from userlogin ul where month(logintime) = 9;
  </code></pre>
  
  <p>I am using Mysql server, any help   </p>