子查询研究

表结构

表名 字段
学生 学号,姓名
课程 课程号,课程名
成绩 学号课程号,分数

如下四个子查询

目的 查询语句
查询选修了任何一门课程的学生 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 学号=学生.学号
        )
    )