|
楼主 |
发表于 2013-4-28 22:55
|
显示全部楼层
本帖最后由 mps777 于 2013-4-29 00:24 编辑
2、全年级多班(初中)的成绩合并分析
二、数据源
初一1班
初一2班
初一3班
任课表
二、三班汇总(全级)
代码:
- select * from [初一1$]
- union all
- select * from [初一2$]
- union all
- select * from [初一3$]
复制代码 二、全级总分前二十名(1:不含名次;2含名次)
不含名次
含名次
代码:
不含次:
- select top 20 班别,姓名,总分 from
- (select * from [初一1$]
- union all
- select * from [初一2$]
- union all
- select * from [初一3$])
- order by 3 desc
复制代码 含名次代码:
- select t2.班别,t2.姓名,t2.总分,(select count(1)+1 from
- (select top 20 初一,班别,姓名,总分 from
- (select '初一' as 初一,* from [初一1$]
- union all
- select '初一',* from [初一2$]
- union all
- select '初一',* from [初一3$]) order by 4 desc)t1 where t1.初一=t2.初一 and t1.总分>t2.总分) as 名次 from
- (select top 20 初一,班别,姓名,总分 from
- (select '初一' as 初一,* from [初一1$]
- union all
- select '初一',* from [初一2$]
- union all
- select '初一',* from [初一3$]) order by 4 desc)t2
复制代码 二、各科班级排名、年级排名
这个用子查询来完成,有点慢。因为都要三表汇总,所以以下的所有分析都是直接取“三班汇总”表数据源来做,目的便于读者阅读。
代码:
- select t2.班别,t2.姓名,
- t2.语文,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.班别=t2.班别 and t1.语文>t2.语文) as 语文班排名,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.一=t2.一 and t1.语文>t2.语文) as 语文级排名,
- t2.数学,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.班别=t2.班别 and t1.数学>t2.数学) as 数学班排名,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.一=t2.一 and t1.数学>t2.数学) as 数学级排名,
- t2.英语,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.班别=t2.班别 and t1.英语>t2.英语) as 英语班排名,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.一=t2.一 and t1.英语>t2.英语) as 英语级排名,
- t2.政治,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.班别=t2.班别 and t1.政治>t2.政治) as 政治班排名,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.一=t2.一 and t1.政治>t2.政治) as 政治级排名,
- t2.总分,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.班别=t2.班别 and t1.总分>t2.总分) as 总分班排名,
- (select count(1)+1 from (select '一' as 一,* from [三班汇总$])t1 where t1.一=t2.一 and t1.总分>t2.总分) as 总分级排名 from
- (select '一' as 一,* from [三班汇总$])t2
复制代码 二、各科全级前十名
代码:
- select 班别,姓名,科目,成绩 from
- (select 班别,姓名,语文 as 成绩,语文*10^3 as 成绩2,'语文' as 科目 from [三班汇总$] where 姓名 in (select top 10 姓名 from [三班汇总$] order by 语文 desc )
- union all
- select 班别,姓名,数学,数学*100,'数学' from [三班汇总$] where 姓名 in (select top 10 姓名 from [三班汇总$] order by 数学 desc )
- union all
- select 班别,姓名,英语,英语,'英语' from [三班汇总$] where 姓名 in (select top 10 姓名 from [三班汇总$] order by 英语 desc )
- union all
- select 班别,姓名,政治,政治,'政治' from [三班汇总$] where 姓名 in (select top 10 姓名 from [三班汇总$] order by 政治 desc )
- union all
- select 班别,姓名,总分,总分*10^4,'总分' from [三班汇总$] where 姓名 in (select top 10 姓名 from [三班汇总$] order by 总分 desc )) order by 成绩2 desc
复制代码 二、各课任老师班级优秀率
1、各教师各班优秀率代码:
- select 授课老师,班别,
- sum(iif(成绩>=85,1,0)) as 优秀人数,count(*) as 班人数,sum(iif(成绩>=85,1,0))/count(*) as 优秀率 from
- (select t1.*,t2.授课老师 from
- (select 班别,语文 as 成绩,'语文' as 科目 from [三班汇总$]
- union all
- select 班别,数学,'数学' from [三班汇总$]
- union all
- select 班别,英语,'英语' from [三班汇总$]
- union all
- select 班别,政治,'政治' from [三班汇总$] )t1 left join [任课表$]t2
- on t1.班别=t2.班别 and t1.科目=t2.科目) group by 班别,授课老师 order by 1
复制代码 2、各教师优秀率
- select 授课老师,
- sum(iif(成绩>=85,1,0)) as 优秀人数,count(*) as 班人数,sum(iif(成绩>=85,1,0))/count(*) as 优秀率 from
- (select t1.*,t2.授课老师 from
- (select 班别,语文 as 成绩,'语文' as 科目 from [三班汇总$]
- union all
- select 班别,数学,'数学' from [三班汇总$]
- union all
- select 班别,英语,'英语' from [三班汇总$]
- union all
- select 班别,政治,'政治' from [三班汇总$] )t1 left join [任课表$]t2
- on t1.班别=t2.班别 and t1.科目=t2.科目) group by 授课老师 order by 1
复制代码 二、各分数段人数
这里是用SQL+数据透视表+分组来完成的……
代码:
- select 班别,姓名,语文 as 成绩,'语文' as 科目 from [三班汇总$]
- union all
- select 班别,姓名,数学,'数学' from [三班汇总$]
- union all
- select 班别,姓名,英语,'英语' from [三班汇总$]
- union all
- select 班别,姓名,政治,'政治' from [三班汇总$]
复制代码 二、全级总分前50名各班人数
代码:
- select 班别,count(*) as 人数 from [三班汇总$] where 姓名 in (select top 50 姓名 from [三班汇总$] order by 总分 desc) group by 班别
复制代码
我的数据表与代码
多个班数据.zip
(62.68 KB, 下载次数: 881)
多个班代码.zip
(1015 Bytes, 下载次数: 730)
|
评分
-
3
查看全部评分
-
|