select 班级,
       sum(iif(排名<11,1,0)) as [1-10名],
       sum(iif(排名>10 and 排名<21,1,0)) as [11-20名],
       sum(iif(排名>20 and 排名<31,1,0)) as [21-30名],
       sum(iif(排名>30 and 排名<41,1,0)) as [31-40名]
from tablename
group by 班级

解决方案 »

  1.   

    select 班级 ,sum (case when 排名 between 1 and 10 then 1 else 0 end) as  1-10名 ,
    sum (case when 排名 between 11 and 20 then 1 else 0 end) as  11-20名 ,
    sum (case when 排名 between 21 and 30 then 1 else 0 end) as  21-30名 ,
    sum (case when 排名 between 31 and 40 then 1 else 0 end) as  11-20名 ,
    from table 
    group  by 班级
      

  2.   

    顺手就贴过来了,忘了这里是SQL版,改iif()为case语句就行了。
      

  3.   

    一楼是ACCESS数据库的二楼是SQL数据库的
      

  4.   

    --二楼的要改一下:select 班级,
    sum (case when 排名 between 1 and 10 then 1 else 0 end) as  [1-10名] ,
    sum (case when 排名 between 11 and 20 then 1 else 0 end) as  [11-20名] ,
    sum (case when 排名 between 21 and 30 then 1 else 0 end) as  [21-30名] ,
    sum (case when 排名 between 31 and 40 then 1 else 0 end) as  [11-20名] ,
    from table 
    group  by 班级