1.查询每个同学的平均成绩,要求按平均分由高到低进行输出
2.查询选修了操作系统课程的学生的学号、姓名和成绩,要求按成绩由高到低进行排序。
select avg(成绩) from 表名 group by 学号 order by avg(成绩) desc
注意数据库表结构,本示例代码如下,students(学生表)和scores(成绩表),通过studentid关联,如果表名和字段名不一样题主自行修改
代码如下,有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~
1
SELECT students.studentid,students.name,avg(score) FROM `scores`,students
where scores.studentid=students.studentid
GROUP BY studentid
order by avg(score) desc
2 假设courseid为课程id,1为操作系统课程id
select students.studentid,students.name,scores.score
from scores,students
where scores.studentid=students.studentid and scores.courseid=1
order by scores.score desc
测试数据如下,scores
students