SELECT d1.cno, d2.pcno FROM Course AS d1, Course AS d2 WHERE d1.pcno = d2.cno
2、查询选课成绩在80分以上的男生姓名、课程名、成绩
1 2 3 4 5 6 7 8 9
SELECT sname, cname, grade FROM ( SELECT sname, cname, grade FROM Student, SC2, Course WHERE Student.sno = SC2.sno and SC2.cno = Course.cno and sex ='M') AS temp(sname, cname, grade) WHERE grade >=60
3、查询没有选修1号课程的学生学号、姓名
1 2 3 4 5
select sno,sname FROM Student WHEREnotEXISTS( SELECT*FROM SC2 WHERE sno = Student.sno and cno ='1' )
4、查询选修了全部课程的学生姓名
1 2 3 4 5 6 7 8 9
-- 查询这样一个学生没有一门课程不选修 select sno,sname FROM Student WHEREnotEXISTS( SELECT*FROM Course --每门课都没选 WHEREnotEXISTS( SELECT*FROM SC2 --某学生选某课 WHERE sno=Student.sno and cno=Course.cno ) )
5、 查询至少选修了学号为1的同学选修的全部课程的学生的学号*
1 2 3 4 5 6 7 8
select sno FROM Student X WHEREnotEXISTS ( SELECT*FROM SC2 Y WHERE Y.sno =1ANDnotEXISTS( SELECT*FROM SC2 Z WHERE X.sno = Z.sno and Y.cno=Z.cno ) )
6、选修了1或2号课的学生学号
1 2 3 4 5 6 7 8 9
-- union 并 -- intersect 交 -- except 差 (SELECT sno FROM SC2 WHERE cno ='1') union ( SELECT sno FROM SC2 WHERE cno ='3' )