查询选课门数等于课程总数的学生学号

查询选课门数等于课程总数的学生学号,student(sno,sname,ssex,sage,sdept)
course(cno,cname,cpno,ccredit)
sc(sno,cno,grade)

select sno from(select sno,count(sno) as num from sc
group by sno
having count(sno)=(select count(cno) from course))tb

查询学生的所有信息用下面的


select * from student where sno in( select sno from(select sno,count(sno) as num from sc
group by sno
having count(sno)=(select count(cno) from course))tb)


img

你可以这样查询
select sno from student s join course c on s.sdept = c.cno group by sno having count(sno) =
(select count(*) from course);

没必要再套一层

select sno from sc
group by sno
having count(sno)=(select count(cno) from course)