三个表:
1、学生表:STUDENT
学号 名字
SID SNAME
1 WAN
2 NAM
3 DNA
2、课程表: COURCE
课号 名字
CID CNAME
1 EN
2 CN
3 US
3、成绩 SC
学号 课程号 得分
SID CID SCORE
1 1 90
1 2 67
1 3 30
2 3 46
3 1 89
--求有参加过课程的人
select sname from student where exists(
select * from cource where exists(
select * from sc where sc.sid=student.Sid and
sc.cid=cource.cid))
--求有 没有参加课程的人
select sname from student where exists(
select * from cource where not exists(
select * from sc where sc.sid=student.Sid and
sc.cid=cource.cid))
--求有参加所有课程的人
select sname from #student where not exists(
select * from cource where not exists(
select * from sc where sc.sid=student.Sid and
sc.cid=cource.cid))