DROP TABLE IF EXISTS "test"."course";
CREATE TABLE "test"."course" (
"cno" varchar(50) NOT NULL,
PRIMARY KEY ("cno")
) ENGINE=InnoDB DEFAULT CHARSET=latin1;//课程表
DROP TABLE IF EXISTS "test"."sc";
CREATE TABLE "test"."sc" (
"sno" varchar(50) NOT NULL,
"cno" varchar(45) NOT NULL,
PRIMARY KEY ("sno","cno")
) ENGINE=InnoDB DEFAULT CHARSET=latin1;//选课表
DROP TABLE IF EXISTS "test"."student";
CREATE TABLE "test"."student" (
"sno" varchar(50) NOT NULL,
PRIMARY KEY ("sno")
) ENGINE=InnoDB DEFAULT CHARSET=latin1;//学生表
//所有 没选择全部课程的学生
select * from student where exists(select * from course where not exists(
select * from sc where student.sno=sc.sno and course.cno=sc.cno
))
//所有 选择全部课程的学生
select * from student where not exists(select * from course where not exists(
select * from sc where student.sno=sc.sno and course.cno=sc.cno
))
//...
参考http://wenku.baidu.com/view/567b4a4333687e21af45a93c.html,但是里面的解释有误,故mark在此
但是文章中对于in和exists的适用范围的描述还是比较有说服力的