要求是这样,比如一个年级的学生的语文考试,要求统计出每班每组的及格人数,
对每一个班的及格人数进行合计。
比如表结构:
学号  班级 小组 成绩
1     1    1   59
2     2    1   61
3     1    2   88
……统计出来下面格式的数据:
班级  小组   及格人数
1     1     2
1     2     4
1     3     0
1     4     6
1           12
2     1     5
2     2     3
2     3     2
2           10
3     1     2
……
求高手指点 !!!!

解决方案 »

  1.   

    比如表结构:
    学号  班级 小组 成绩select 班级,小组,count(*) from tablename
    where 成绩>=60
    group by 班级,小组
    union
    select 班级,'',count(*) from tablename
    where 成绩>=60
    group by 班级
    order by 1,2
      

  2.   

    select 班级,小组,及格人数=count(*) 
    from tablename
    where 成绩>=60
    group by 班级,小组
    union all
    select 班级,'',及格人数=sum(1) from tablename
    where 成绩>=60
    group by 班级
      

  3.   

    select class,group,grade
    from table
    where grade>=60
    group by rollup(class,group)//group by rollup有生成数据统计,横向小计和总计统计的功能
      

  4.   

    谢谢大家,找到合适的语句了,因为只要小计,所以这样:
    select class,group,grade
    from table
    where grade>=60
    group by class,rollup(group)
    order by class,group