[英]Understanding nested SQL statement
有没有简单的方法可以重新创建此语句? 还是我可以在数据库中查找示例的方法? 因为目前我还不知道它到底能做什么。 我想我理解第一个示例in
但是我不知道为什么PROJECTS会有两个in
子句,为什么第二个示例与第一个示例不同。 提前致谢。
select usernumber as usrnr from DOCUMENTS
where CompanyIndex in (
select CompanyIndex
from DOCUMENTS
where DocumentType='3'
and ProjectsIndex in (select Index
from PROJECTS where
Projectnumber = 209806)
)
and ProjectsIndex in (
select Index
from PROJECTS
where Projectnumber = 209806
)
and DocumentType = '2'
我不明白为什么它与此不同
select ad1 as AD1Nr from DOCUMENTS
where CompanyIndex in
(
select CompanyIndex
from DOCUMENTS
where DocumentType='3'
and ProjectsIndex in (select Index
from PROJECTS
where Projectnumber = 209806)
and DocumentType = '2')
我已经重新格式化了代码以显示结构。
区别现在很明显:条件DocumentType = '2'
在第二个样本的内部选择内部,而在第一个样本的外部。
(这就是为什么对格式有些过分强迫不是负面特征。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.