用SQL语句,实现
能统计出各分数段的学生人数如
————————————————————————————————
分数段   人数
0          21
1~9       54
10~19     46
20~29     55
30~39     84
40~49     48
50~59     95
60~69     25
70~79     84
80~89     39
90~99     65
100        99————————————————————————————————
高手指导

解决方案 »

  1.   

    select count(*) from 表
    where 分数 between 1 and 9
      

  2.   

    declare @a table(id int,fs int)
    insert into @a select 1,1
    union all
    select 2,9
    union all
    select 3,10
    union all
    select 4,19
    union all
    select 5,20
    union all
    select 6,29
    union all
    select 7,30
    select count(*) from @a 
    where fs between 1 and 20
      

  3.   

    select count(*),分数/10from  表group by 分数/10
      

  4.   

    select 分数段 , 人数 = count(*) from
    (
      select 分数 , 分数段 = case
        when 分数 = 0 then '0' 
        when 分数 between 0  and 9  then '1~9'
        when 分数 between 10 and 19 then '10~19'
        when 分数 between 20 and 29 then '20~29'
        when 分数 between 30 and 39 then '30~39'
        when 分数 between 40 and 49 then '40~49'
        when 分数 between 50 and 59 then '50~59'
        when 分数 between 60 and 69 then '60~69'
        when 分数 between 70 and 79 then '70~79'
        when 分数 between 80 and 89 then '80~89'
        when 分数 between 90 and 99 then '90~99'
        when 分数 = 100 then '100'
        end
      from tb 
    ) t
    group by 分数段
      

  5.   

    --另外一种写法.
    select 分数段 = '0' , 人数 = count(*) from tb where 分数 = 0 
    union all
    select 分数段 = '1~9' , 人数 = count(*) from tb where 分数 between 0  and 9
    union all
    select 分数段 = '10~19' , 人数 = count(*) from tb where 分数 between 10  and 19
    union all
    select 分数段 = '20~29' , 人数 = count(*) from tb where 分数 between 20  and 29
    ......
    union all
    select 分数段 = '90~99' , 人数 = count(*) from tb where 分数 between 90  and 99
    union all
    select 分数段 = '100' , 人数 = count(*) from tb where = 100