title: How to use a temp column in the where clause
body: <p>Why can't I use a temporary column in the where clause?</p>
  
  <p>For example, this query:</p>
  
  <pre><code>Select 
      product_brand, 
      (CASE WHEN COUNT(product_brand)&gt;50 THEN 1 ELSE 0 END) AS brand_count 
  FROM 
      products 
  WHERE 
      1 
  GROUP BY 
      product_brand
  </code></pre>
  
  <p>This brings up two columns, one called <code>product_brand</code> and one called <code>brand_count</code>. <code>brand_count</code> is created on the fly and is always 1 or 0 depending on whether or not there are 50 or products with that brand.</p>
  
  <p>All this makes sense to me, except that I can't select only if <code>brand_count = 1</code> as in this query below:</p>
  
  <pre><code>Select 
      product_brand, 
     (CASE WHEN COUNT(product_brand)&gt;50 THEN 1 ELSE 0 END) AS brand_count 
  FROM 
      products 
  WHERE 
     brand_count = 1 
  GROUP BY 
     product_brand
  </code></pre>
  
  <p>which gives me this error:</p>
  
  <pre><code>#1054 - Unknown column 'brand_count' in 'where clause' 
  </code></pre>