この質問に似たシナリオを想定してください。次の結果を取得したい:
score range | number of occurrences
-------------------------------------
0-9 | 11
10-19 | 14
20-29 | 3
... | ...
そして、選択した回答を解決策として使用できます。
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
30 ~ 39 の範囲の結果が表示されない場合でも、その範囲のスコアが表示されるようにするにはどうすればよいですか?