帮助理解为什么错误的内部查询不会使外部查询错误
以下查询返回19
proc sql;
select count(distinct name)
from sashelp.class
where name in (select name from sashelp.iris
where species is not missing)
;quit; *returns 19;
Run Code Online (Sandbox Code Playgroud)
但是,我希望它会返回一个错误,因为内部查询确实会返回一个错误(因为在sashelp.iris中找不到“名称”列):
proc sql;
select name from sashelp.iris
where species is not missing
;quit; *returns an error (column not found);
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下为什么我一开始没有收到错误消息的逻辑吗?
您没有限定引用的资格,name因此它使用了唯一的变量,即名称。因此,您运行了以下查询:
proc sql;
select count(distinct A.name)
from sashelp.class A
where A.name in
(select A.name
from sashelp.iris B
where B.species is not missing
)
;
quit;
Run Code Online (Sandbox Code Playgroud)
如果您实际上从IRIS引用了NAME,则会收到错误消息。
220 proc sql;
221 select count(distinct A.name)
222 from sashelp.class A
223 where A.name in
224 (select B.name
225 from sashelp.iris B
226 where B.species is not missing
227 )
228 ;
ERROR: Column name could not be found in the table/view identified with the correlation name B.
ERROR: Unresolved reference to table/correlation name B.
229 quit;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58 次 |
| 最近记录: |