Return to Snippet

Revision: 32784
at October 2, 2010 05:18 by daipratt


Initial Code
SELECT price_range, count(*) AS num
FROM
(select case when product_price >= 150 and product_price <= 249.99 then '150-249.99'
             when product_price >= 250 and product_price <= 299.99 then '250-299.99'
             when product_price >= 300 and product_price <= 399.99 then '300-399.99'
             when product_price >= 400 and product_price <= 499.99 then '400-499.99'
             when product_price >= 500 and product_price <= 999.99 then '500-999.99'
             else 'over 1000'
         end as price_range
FROM washing_machines
WHERE 1
) AS  price_summaries
GROUP BY price_range

Initial URL
http://daipratt.co.uk/tag/mysql/

Initial Description
Group by user defined price bands.

Initial Title
MySQL - Group by price range

Initial Tags
mysql

Initial Language
MySQL