3、分数表 score:
±---------±------±-------±------+
| courseID | stuID | course | score |
±---------±------±-------±------+
| 2 | 1001 | 数学 | 73 |
| 3 | 1001 | 英语 | 79 |
| 1 | 1001 | 语文 | 81 |
| 3 | 1002 | 英语 | 87 |
| 2 | 1002 | 数学 | 83 |
| 1 | 1002 | 语文 | 79 |
| 1 | 1003 | 语文 | 65 |
| 3 | 1003 | 英语 | 65 |
| 2 | 1003 | 数学 | 97 |
| 1 | 1004 | 语文 | 78 |
| 3 | 1004 | 英语 | 78 |
| 2 | 1004 | 数学 | 86 |
| 1 | 1005 | 语文 | 67 |
| 3 | 1005 | 英语 | 88 |
| 2 | 1005 | 数学 | 89 |
| 2 | 1006 | 数学 | 90 |
| 3 | 1006 | 英语 | 92 |
| 1 | 1006 | 语文 | 98 |
| 1 | 1007 | 语文 | 85 |
| 2 | 1007 | 数学 | 78 |
| 3 | 1007 | 英语 | 72 |
| 1 | 1008 | 语文 | 78 |
| 3 | 1008 | 英语 | 77 |
| 2 | 1008 | 数学 | 85 |
| 3 | 1009 | 英语 | 94 |
| 2 | 1009 | 数学 | 91 |
| 1 | 1009 | 语文 | 68 |
±---------±------±-------±------+
1、查询各班各科分数最高的学生学号,姓名,班级名称,科目名称,分数:
MySQL>
create table ab_all_cl_st_sc as select st.stuid as 学号 , st.stuname as 姓名 , l.classname as 班级, sc.course as 科目, sc.score as 成绩 from ab_class cl , ab_student st , ab_score sc where cl.classid=st.classid and st.stuid=sc.stuid
MySQL>
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘一班’ and tt.科目=‘语文’)
union all
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘一班’ and tt.科目=‘数学’)
union all
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘一班’ and tt.科目=‘英语’)
union all
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘二班’ and tt.科目=‘语文’)
union all
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘二班’ and tt.科目=‘数学’)
union all
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘二班’ and tt.科目=‘英语’)
union all
select * from AB_ALL_CL_ST_SC t where t.科目=‘语文’ and t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘三班’ and tt.科目=‘语文’)
union all
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘三班’ and tt.科目=‘数学’)
union all
select * from AB_ALL_CL_ST_SC t where t.成绩=(
select max(tt.成绩) from AB_ALL_CL_ST_SC tt where tt.班级=‘三班’ and tt.科目=‘英语’)
结果:
如下代码效果不佳
MySQL>select max(成绩),班级,科目 from AB_ALL_CL_ST_SC t group by 班级,科目
结果
font face=“微软雅黑” color=#FF8C00 size=3> 修改颜色
oracle查询各个年级的总分数 1 查询各班各科分数最高的学生学号 姓名 班级名称 科目名称 分数:...