Đúng. Bạn thực hiện phân vùng trong CASE
clase.
SELECT
COUNT(*),
CASE
WHEN age < 1 THEN 'age1'
WHEN age BETWEEN 1 AND 4 THEN 'age2'
WHEN age BETWEEN 4 AND 9 THEN 'age3'
ELSE 'age4'
END AS ageband
FROM children
GROUP BY ageband;