日期:2014-05-17  浏览次数:20739 次

百分求一统计问题的解决办法!!!
要求是这样,比如一个年级的学生的语文考试,要求统计出每班每组的及格人数,
对每一个班的及格人数进行合计。
比如表结构:
学号     班级   小组   成绩
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
------解决方案--------------------
select 班级,小组,及格人数=count(*)
from tablename
where 成绩> =60
group by 班级,小组
union all
select 班级, ' ',及格人数=sum(1) from tablename
where 成绩> =60
group by 班级

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