假设我有一个带有数字列的表(我们称其为“分数”)。
我想生成一个计数表,该表显示每个范围内得分出现的次数。
例如:
分数范围| 出现次数 ------------------------------------- 0-9 | 11 10-19 | 14 20-29 | 3 ... | ...
在此示例中,有11行的分数在0到9之间,有14行的分数在10到19之间,还有3行的分数在20-29之间。
有没有简单的方法来进行设置?你有什么建议吗?
在SQL Server 2000上,投票率最高的答案均不正确。也许它们使用的是其他版本。
这是它们在SQL Server 2000上的正确版本。
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
要么
select t.range as [score range], count(*) as [number of occurrences]
from (
select user_id,
case when score >= 0 and score< 10 then '0-9'
when score >= 10 and score< 20 then '10-19'
else '20-99' end as range
from scores) t
group by t.range
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句