title: How to use an aliased column in a MySQL WHERE clause?
body: <p>I have a MySQL query like this:</p>
  
  <pre><code>SELECT *, SUM(...some SQL removed for brevety) AS Occurrences FROM some_table AS q
  WHERE criterion="value" GROUP BY q.P_id ORDER BY Occurrences DESC LIMIT 10;
  </code></pre>
  
  <p>I want to restrict the results to rows where Occurrences>0.  This seems very simple to me, but I can't seem to make it work.  No matter what I try, WHEREs or HAVINGs, whenever I try to add this restriction I get NO ROWS in return.  I'm positive that there is data in my table that should be returned.  Does anyone know how to accomplish what I'm doing?</p>
  
  <hr>
  
  <p>I've tried this, but it still doesn't work.  Any ideas why it still won't work?</p>
  
  <pre><code>SELECT *, SUM(...some SQL removed for brevety) AS Occurrences FROM some_table AS q
  WHERE criterion="value" HAVING SUM(...some SQL removed for brevety)&gt;0 GROUP BY q.P_id ORDER BY Occurrences DESC LIMIT 10;
  </code></pre>