title: Conditional count in mysql
body: <p>I have a table <code>user_login</code> with two rows, userId and tstamp (user id and timestamp of login).</p>
  
  <p>Counting the number of logins is simple:</p>
  
  <pre><code>SELECT userId, COUNT(*) as logins FROM user_login GROUP BY userId;
  </code></pre>
  
  <p>Counting the number of logins before a certain date (e.g. Jan 1 2018) is also simple:</p>
  
  <pre><code>SELECT userId
       , COUNT(*) as loginsBeforeJan1 
    FROM user_login 
   WHERE tstamp &lt; '2018-01-01' 
   GROUP 
      BY userId;
  </code></pre>
  
  <p>How can I have both results in one table? I tried </p>
  
  <pre><code>SELECT userId
       , COUNT(*) as logins
       , COUNT(IF(tstamp &lt; '2018-01-01',1,0)) loginsBeforeJan1 
    FROM user_login 
   GROUP 
      BY userId;
  </code></pre>
  
  <p>but both the logins and loginsBeforeJan1 are identical.</p>
  
  <p>How can I modify the query to produce the result I want?</p>