Suppose a scenario similar to this question. I want to get the following results:
score range | number of occurrences
-------------------------------------
0-9 | 11
10-19 | 14
20-29 | 3
... | ...
And I can use the selected answer as a solution:
select t.range as [score range], count(*) as [number of occurences]
from (
select case
when score between 0 and 9 then ' 0- 9'
when score between 10 and 19 then '10-19'
else '20-99' end as range
from scores) t
group by t.range
How can I assure that the score range of 30-39 will be display even when there are no results on that range?