假设一个类似于这个问题的场景。我想得到以下结果:
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 的分数范围?