[英]How To group product price as range and list in navigation as shop by price using php
<!-- language: lang-sql -->
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
Can any one explain this with an example? 有人可以举例说明吗?
This is a simple query. 这是一个简单的查询。 If you have a table with several price you select the price_range and the number of occurrency of each price_range.
如果您有一个包含多个价格的表,则选择price_range以及每个price_range的出现次数。
The price_range is calculated by a select with CASE
and for each WHEN
staement you get a different price_range. 该PRICE_RANGE通过选择与计算
CASE
和每个WHEN
staement你会得到不同的PRICE_RANGE。
I hope this could be useful for you 我希望这对您有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.