展开全部
请参考下列SQL语句:selectstudent.sno,student.sname,student.sdept,
ame,t.maxgradefrom
student,course,
(selects.sno,c.sdept,o,c.maxgrade
fromscs,studentst,
(selecta.sdept,o,max(b.grade)asmaxgrade
fromstudenta,scbwherea.sno=b.sno
groupbya.sdept,o)c
wheres.sno=st.snoandst.sdept=c.sdeptand
s.grade=c.maxgrade)twherestudent.sno=t.sno
o=ame,student.sdept;
上述语句已经测32313133353236313431303231363533e4b893e5b19e31333365646330试通过。代码思路是:
学生表与成绩表基于学号进行连接获取每个学号所在系名,然后用院系和课程号对成绩表分组汇总,求得每个院系、每个课程的最高得分(结果集c,含系名、课程号和最高分)。然后用结果集C再次与成绩表、学生表进行比对,筛选出获得每个系、每个课程的最高分的学号并包含课程号和系名(结果集t)。最后t通过连接获取学生表中的学生姓名、课程表中的课程名完成最后输出。