先上图:以下分别是SC(分数表)、Course(课程表),SC(分数表)
需求一:查询平均分数大于60分的学号与平均成绩
实现的sql语句:select Sid as ‘学号‘,(select avg(score) from Student where Student.Sid=SC.Sid) as ‘平均成绩‘ from SC where (select avg(score) from SC Student where Student.Sid=SC.Sid)>60;
需求二:查询所有同学的学号,姓名,选课数,总成绩
实现的SQL语句:select Sid as ‘学号‘,Sname as ‘姓名‘,(select count(Sid) from SC where student.Sid=sc.Sid) as ‘选课数‘,(select sum(Score) from SC where student.Sid=sc.Sid) as ‘总成绩‘ from Student;
需求三:查询学生001的所有成绩,并倒序排序
实现的SQL语句|:select * from SC where Sid=001 by desc;
2019年7月25日||一道数据库面试题,使用到了MySql函数avg(),count()
原文:https://www.cnblogs.com/zhaoyugang/p/11246058.html