我正在学习SQL,在我的大学里,我正在练习这个练习并卡住了!我有一个数据库,存储学生为特定教学而通过的所有考试。练习帮助 - 选择平均得分最高的学生的注册号
这些都在数据库中的表:
Student(**number**, name, birthday)
Exam(**student_number**, **teaching_code**, vote) *(store the exams passed by the students with vote)*
Teaching(**code**, name)
凡号是学生表的主键和代码是在学生教学,“student_number”引用“数字”和“teaching_code”在教学中引用“代码”。
练习要求选择平均得分最高的学生数字。
我知道如何编写一个查询,该查询给了我一张包含每个学生平均数的表格,但我不知道如何从中选择最高或者如何显示相应的学生数字!
与limit命令的解决方案,如果存在一些学生具有相同的最高平均不工作...
显示每个学生的平均成绩查询是:
select avg(e.vote) as Average from STUDENT s, EXAM e
where s.number = e.student_number
group by s.number
编辑: 我试过SQL中的MAX功能,我已经试过这样:
select MAX(avg(e.vote)) as Average from STUDENT s, EXAM e
where s.number = e.student_number
group by s.number
但它说:“错误代码:1111无效使用组功能的”
可能解决方案是嵌套查询,但我无法实现它。
因为这是作业,你应该发布你已经尝试过的东西。 – Taryn 2012-07-26 14:28:32