| 表名 | 字段 |
|---|---|
| 学生 | 学号,姓名 |
| 课程 | 课程号,课程名 |
| 成绩 | 学号,课程号,分数 |
| 目的 | 查询语句 |
|---|---|
| 查询选修了任何一门课程的学生 | select * from 学生 where exists ( select * from 课程 where exists ( select * from 成绩 where 课程号=课程.课程号 and 学号=学生.学号 ) ) |
| 查询没有选修全部课程的学生 | select * from 学生 where exists ( select * from 课程 where not exists ( select * from 成绩 where 课程号=课程.课程号 and 学号=学生.学号 ) ) |
| 查询没有选修一门课程的学生 | select * from 学生 where not exists ( select * from 课程 where exists ( select * from 成绩 where 课程号=课程.课程号 and 学号=学生.学号 ) ) |
| 查询选修每门课程的学生 | select * from 学生 where not exists ( select * from 课程 where not exists ( select * from 成绩 where 课程号=课程.课程号 and 学号=学生.学号 ) ) |