查询选修了全部课程的学生名

三张表:学生表student (Sno,Sname),  课程表course (Cno,Cname), 选课表SC(Sno,Cno)

--选修了全部课程的学生名

select  Sname from student where Sno in 
(select Sno from SC group by Sno having count(*) =(select count(*) from course))

--选修了部分课程的学生名

select  Sname from student where Sno in 
(select Sno from SC group by Sno having count(*) <(select count(*) from course))

--没有选修课程的学生名

select  Sname from student where Sno not in
(select Sno from SC inner join course on SC.Cno = course.Cno group by Sno
)
原文地址:https://www.cnblogs.com/shaosks/p/5239306.html