数据库如下:
序号   姓名  成绩
1   张三  89
2   李四  76
3   王五  85
4   赵六  66
5   某某  45
现在要求汇总如下:90分以上   85-90  70-85  60-70  60以下
0       2     1    1     1

解决方案 »

  1.   

    select sum(case when 成绩>90 then 1 else 0 end)[90分以上],
     sum(case when 成绩<=90 and  成绩>80 then 1 else 0 end)[90分以上],
    from
    biao
      

  2.   

    select 
      sum(case when 成绩>=90 then 1 else 0 end) as [90分以上],
      sum(case when 成绩>=85  and 成绩<90 then 1 else 0 end) as [85-90],
      sum(case when 成绩>=70  and 成绩<85 then 1 else 0 end) as [70-85],
      sum(case when 成绩>=60  and 成绩<70 then 1 else 0 end) as [60-70],
      sum(case when 成绩<60 then 1 else 0 end) as [60以下]
    from test
      

  3.   

    select sum(case when 成绩>90 then 1 else 0 end)[90分以上],
     sum(case when 成绩<=90 and  成绩>85 then 1 else 0 end)[85-90]
    --...同上
    from
    biao
      

  4.   

    create table #table1 ( a  int,   b char(10),   c int)
    insert into #table1 
    select   1,'张三',89  union
    select   2,'李四',64   union
    select   3,'五',85   union
    select   4,'赵六',66   union
    select   5,'某某',45   select * from #table1select  (select count(*) from #table1 where c>=90), 
           (select count(*) from #table1 where 90 > c and c>=85 )   ,  
          (select count(*) from #table1 where 85>c and c>=70)    , 
         (select count(*) from #table1 where 70>c and c > 60) ,
        (select count(*) from #table1 where c< 60)
      

  5.   

    gaolch(“好男儿”这个名字真肉酸)
    不好意思,可能是我给分的时候你回的贴子