标签:sum 生成 检索 net having exist 遍历 select style
https://blog.csdn.net/wolfofsiberian/article/details/39346781#
学生表
课程表
分数表
1、检索出选了全部课程的学生姓名:
(不存在一门课程没有分数)
SELECT student.SNAME from student
where not EXISTS
(
SELECT * from course
where NOT EXISTS
(
SELECT * from sc
where sc.SNO = student.SNO and sc.CNO = course.CNO
)
);
理解:exists是每层向下遍历,每层结果放到当层结果集里,not exists 若内层结果集为空则上一层的值放到结果集合。
student { 对于某个人
course { 不存在一门可能
sc{ 他没有分数记录
sc.SNO = student.SNO &&
sc.CNO = course.CNO
}
}
}
https://blog.csdn.net/songxueyu/article/details/9140061
1.1、检索至少选修"程军"老师所授全部课程的学生姓名
SELECT student.SNAME from student
where not EXISTS
(
SELECT * from course
where course.TEACHER = ‘程军‘ AND NOT EXISTS
(
SELECT * from sc
where sc.SNO = student.SNO and sc.CNO = course.CNO
)
);
执行顺序:from > join > on > where > group by > avg.sum.count.... .. > having > select > distinct > order by
distinct 优先级高于order by 连用时order by 的字段必须在 select 中,否则distinct生成的虚拟表无order by字段。
标签:sum 生成 检索 net having exist 遍历 select style
原文地址:https://www.cnblogs.com/tommaoxiaoqi/p/12700321.html