要求是这样,比如一个年级的学生的语文考试,要求统计出每班每组的及格人数,
对每一个班的及格人数进行合计。
比如表结构:
学号 班级 小组 成绩
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 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
……
求高手指点 !!!!
学号 班级 小组 成绩select 班级,小组,count(*) from tablename
where 成绩>=60
group by 班级,小组
union
select 班级,'',count(*) from tablename
where 成绩>=60
group by 班级
order by 1,2
from tablename
where 成绩>=60
group by 班级,小组
union all
select 班级,'',及格人数=sum(1) from tablename
where 成绩>=60
group by 班级
from table
where grade>=60
group by rollup(class,group)//group by rollup有生成数据统计,横向小计和总计统计的功能
select class,group,grade
from table
where grade>=60
group by class,rollup(group)
order by class,group