title: select sum where sum
body: <p>I want to select some entries based on a max+sum condition.</p>
  
  <pre><code>mytable
  ----------
  id | col1 | col2
  </code></pre>
  
  <p>I want to select all entries that have  the sum of col1 &amp; col2 greater than or equal to the max of sum minus X. (don't ask me why :) )</p>
  
  <p>So far I managed to get the sum OK (hereafter aliased as "total") with:</p>
  
  <pre><code>SELECT id,SUM(col1 + col2) AS total FROM mytable GROUP BY id;
  </code></pre>
  
  <p>I also managed to get the MAX of the sum OK (with a ORDER BY/LIMIT workaround though):</p>
  
  <pre><code>SELECT id,SUM(col + col) as total FROM mytable GROUP BY id ORDER BY total DESC LIMIT 1;
  </code></pre>
  
  <p>However everytime I try to re-use my alias as a condition (e.g. WHERE total >= ...) I get an <strong>"Unknown column" error</strong></p>
  
  <p>Anything would be greatly appreciated</p>