title: Several COUNTs with conditions in MySQL
body: <p>I'm currently working on a hit counter with some other statistics, like percentage of the visitors being logged in and so forth.</p>
  
  <p>I've tried many different SQL queries so far, but currently I'm stuck with this:</p>
  
  <pre><code>SELECT COUNT(*) AS totalhits,
  COUNT(DISTINCT ip) AS visitors,
  COUNT(user_id &gt; 0) AS hitsloggedin,
  COUNT(DISTINCT ip, user_id &gt; 0) AS visitorsloggedin
  FROM db.tblhits
  </code></pre>
  
  <p>Apparently this is wrong. I'm getting all rows counted in the third and fourth COUNT statement although there are rows where user_id is 0. The two first statements works just fine, though.</p>
  
  <p>I'm sure someone is laughing his ass off now, but this is what I've tried with.</p>
  
  <p>Any nudge in the right direction would be greatly appreciated!</p>