SELECT CASE WHEN age IS NULL THEN 'Unspecified'
WHEN age < 18 THEN '<18'
WHEN age >= 18 AND age <= 24 THEN '18-24'
WHEN age >= 25 AND age <= 30 THEN '25-30'
WHEN age >= 31 AND age <= 40 THEN '31-40'
WHEN age > 40 THEN '>40'
END AS ageband,
COUNT(*)
FROM (SELECT age
FROM table) t
GROUP BY ageband
This is my request. Here are the results:

However, if table.age does not have at least 1 age in the category, it will be simply flat, ignoring this case as a result. For example:

There were no records of age <18 in this dataset. Thus, the age bar "<18" does not appear. How can I do this so that it displays and returns the value 0 ??
source
share