title: SQL: How to filter after aggregation?
body: <p>It is very easy to remove values that you don't want aggregated.</p>
  
  <p>For instance:</p>
  
  <pre><code>SELECT department, SUM(sales) as "Total sales"
  FROM order_details
  GROUP BY department
  HAVING SUM(sales) &gt; 1000;
  </code></pre>
  
  <p>Which will exclude all sales with a value less than or equal to 1000 from the summing aggregation.</p>
  
  <p>But how do you filter after the aggregation?</p>
  
  <p>E.g. <code>WHERE ("Total sales"&gt; 15000)</code></p>
  
  <p>Edit: Ironically I was only including <code>HAVING SUM(sales) &gt; 1000;</code> in order to prevent confusion about the type of query required; because I'm not actually interested in excluding items from the summing, just the returned results! Thanks, despite confusion!</p>