教你彻底懂了 查询选修全部课程的学生姓名 sql双重否定用法!
前提了解
1. 这是 where字段的多行多列子查询
2. sql 架构:
select 学生
from 学生表,课程 表
where (课程 = 全部课程)= true;
分析一
双重否定法 (把每个select看成是一个条件) //@
select *
from s
where not exists
(select * from c
where not exists
(select * from sc where sc.SNO =s.SNO and sc.CNO=c.CNO))
条件A : select * from sc where sc.SNO =s.SNO and sc.CNO=c.CNO where是1,则A= 1 ;
条件B: select * from c where !A !A= 0,结果 B=0 ;
条件c: select * from where !B 看如下分析;
条件c 取 B的反结果;
而 !B --> select * from c --> 要得到全部课程
--> !A --> A --> 条件A要继续成立
分析二
select 学生
where (课程 = 全部课程) = true
1. “课程”
要是学生选择的课程
select * from sc where sc.SNO =s.SNO and sc.CNO=c.CNO
2. 全部课程
select * from c
3. 把 (课程 = 全部课程) = true 变成双重否定
!(!课程 = !全部课程)
4.
where not exists
(select * from c
where not exists
(select * from sc where sc.SNO =s.SNO and sc.CNO=c.CNO))
结束! 转载请注明出处!