カテゴリごとの最小価格と最大価格の場合:
SELECT category, min(price) as min_price, max(price) as max_price
from Products
Group BY category
クエリで直接範囲の場合、次のようなことができます
SELECT
category,
SUM(CASE WHEN price BETWEEN 0 AND 5 THEN 1 ELSE 0 END) as zero-five,
SUM(CASE WHEN price BETWEEN 5 AND 10 THEN 1 ELSE 0 END) as five-ten,
...
from Products
Group BY category
収量
Category zero-five five-ten
Cat1 2 4
Cat2 3 6
また
SELECT category, range, count(*)
FROM (
SELECT
category,
CASE WHEN price BETWEEN 0 to 5 THEN '0-5'
WHEN price BETWEEN 5 to 10 THEN '5-10'
...
ELSE '10+'
END as range
FROM products
)
group by category, range
収量
Category range count
Cat1 0-5 2
Cat1 5-10 4
Cat1 10+ 0
Cat2 0-5 3
Cat2 5-10 6
Cat2 10+ 0