- 查询所有的课程的名称及对应的任课老师
- select course.cname, teacher.tname from course inner join teacher on course.teacher_id=teacher.tid;
- 查询平均成绩大于80的同学的姓名
- select student.sname, t1.avg_score from student inner join (select score.student_id, avg(num) as avg_score from score inner join student on score.student_id=student.sid group by score.student_id having avg(num)>80) as t1 on student.sid=t1.student_id;
- 查询没有报李平老师课的学生姓名
- select student.sname from student where student.sid not in (select distinct score.student_id from score where score.course_id in (select course.cid from teacher inner join course on teacher.tid=course.teacher_id where teacher.tname = '李平老师'));
- 查询没有同时选修物理课程和体育课程的学生姓名
- select student.sname from student where student.sid in (select score.student_id from score where score.course_id in (select course.cid from course where course.cname in ('物理','体育')) group by score.student_id having count(score.course_id) = 1);
- 查询挂科超过两门(包括两门)的学生姓名和班级
- select class.cid,t1.sname from class inner join (select student.class_id from student where student.sid in (select score.student_id from score where score.num<60 group by score.student_id having count(score.course_id)>=2) as t1) on class.cid=t1.class_id;