查询没学过“张磊老师”课的同学的学号、姓名
首先还是先找到要使用的表,这道题表的关系比较复杂,要三表进行关联
from teacher join course on teacher.tid=course.teacher_id
right join score on course.cid =score.course_id
join student on student.sid=score.student_id
然后在分组之前将条件“张磊老师”筛选出来
where tname!='张磊老师'
然后将学生编号进行分组,再计数老师的课程
group by student_id
having count(tname)=1
最后得到