SELECT DISTINCT Sno
FROM SC
WHERE Sno NOT IN
(SELECT Sno
FROM SC
WHERE Cno='1' AND Sno IN
(SELECT Sno
FROM SC
WHERE Cno='5'))
这是一般的变法,还可用集合查询,关键字INTERSECT
SELECT DISTINCT Sno
FROM SC
WHERE Sno NOT IN
(SELECT Sno
FROM SC
WHERE Cno='1'
INTERSECT
SELECT Sno
FROM SC
WHERE Cno='5')
追答select s.学号
from student s,course c,SC sc
where s.学号=sc.学号 and c.课程号=sc.课程号 and
c.课程号='1'
union
select s.学号
from student s,course c,SC sc
where s.学号=sc.学号 and c.课程号=sc.课程号 and
c.课程号='2'