MySQL - Group by price range


/ Published in: MySQL
Save to your folder(s)

Group by user defined price bands.


Copy this code and paste it in your HTML
  1. SELECT price_range, count(*) AS num
  2. (select case when product_price >= 150 and product_price <= 249.99 then '150-249.99'
  3. when product_price >= 250 and product_price <= 299.99 then '250-299.99'
  4. when product_price >= 300 and product_price <= 399.99 then '300-399.99'
  5. when product_price >= 400 and product_price <= 499.99 then '400-499.99'
  6. when product_price >= 500 and product_price <= 999.99 then '500-999.99'
  7. else 'over 1000'
  8. end as price_range
  9. FROM washing_machines
  10. ) AS price_summaries
  11. GROUP BY price_range

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.