for example this query:
Select
product_brand,
(CASE WHEN COUNT(product_brand)>50 THEN 1 ELSE 0 END) AS brand_count
FROM
products
WHERE
1
GROUP BY
product_brand
This brings up 2 columns one called product_brand and one called brand_count, brand_count is created on the fly and is always 1 or 0 depending on whether or not there are 50 or products with that brand.
OK all this makes sense to me....but what does not make sense to me is that I can't select only if brand_count = 1 as in this query below:
Select
product_brand,
(CASE WHEN COUNT(product_brand)>50 THEN 1 ELSE 0 END) AS brand_count
FROM
products
WHERE
brand_count = 1
GROUP BY
product_brand
gives me this error: *#1054 - Unknown column 'brand_count' in 'where clause'*