时间:2021-07-01 10:21:17 帮助过:4人阅读
2、查询“生物”课程比“物理”课程成绩高的所有学生的学号;
select A.student_id from (select student_id,num from score LEFT JOIN course on score.course_id=course.cid WHERE course.cname="生物") as A INNER JOIN (select student_id,num from score LEFT JOIN course on score.course_id=course.cid WHERE course.cname="物理") as B ON A.student_id=B.student_id WHERE A.num > B.num
3、查询平均成绩大于60分的同学的学号、名字和平均成绩;
select student.sid,student.sname,B.numname from (select student_id,avg(num) as numname from score GROUP BY student_id HAVING AVG(num)>60) as B LEFT JOIN student on B.student_id=student.sid
4、查询所有同学的学号、姓名、选课数、总成绩;
SELECT student_id,student.sname,COUNT(course_id),SUM(num) from score LEFT JOIN student on score.student_id=student.sid GROUP BY student_id
5、查询姓“李”的老师的个数;
select * from teacher WHERE tname like "李%"
6、查询没学过“李平”老师课的同学的学号、姓名;
SELECT student.sid,student.sname from student WHERE student.sid not in ( SELECT student_id from score WHERE score.course_id in (select course.cid from course LEFT JOIN teacher on course.teacher_id=teacher.tid WHERE teacher.tname="李平老师") GROUP BY student_id)
MySQL练习题参考答案
标签:rom for bsp opened cap localhost nod 技术分享 nsf