select
sth.sno,
sth.sname
from student sth,
(select * from sc where sno='s002') a,
(select * from sc where sno<>'s002') b
where
b.sno=sth.sno
having
sum(case when a.cno=b.cno then 0 else 1 end) --使用case进行计数
=
(select count(cno) from sc where sno='s002')
group by sth.sno,sth.sname
select student.sno,student.sname from student where student.sno in(
select sc.sno from sc where sc.sno != 's002'
and sc.cno in (
select cno from sc where sc.sno = 's002'
) group by sc.sno
having count(sc.cno) = (select count(cno) from sc where sc.sno = 's002' )
intersect
select sc.sno from sc where sc.sno != 's002' group by sc.sno
having count(sc.cno) = (select count(cno) from sc where sc.sno = 's002')
);