为什么错误的内部查询不会使外部查询错误
Why does erroneous inner query not make outer query erroneous
帮助理解为什么错误的内部查询不会使外部查询错误
下面查询returns 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;
但是,我希望它 return 一个 错误 ,因为内部查询确实 return 一个错误(因为列 'name' 在 sashelp.iris 中找不到):
proc sql;
select name from sashelp.iris
where species is not missing
;quit; *returns an error (column not found);
有人能解释一下为什么我一开始没有收到错误消息的逻辑吗?
您没有限定对 name
的引用,因此它使用了它找到的唯一名为 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;
如果您实际上从 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;
帮助理解为什么错误的内部查询不会使外部查询错误
下面查询returns 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;
但是,我希望它 return 一个 错误 ,因为内部查询确实 return 一个错误(因为列 'name' 在 sashelp.iris 中找不到):
proc sql;
select name from sashelp.iris
where species is not missing
;quit; *returns an error (column not found);
有人能解释一下为什么我一开始没有收到错误消息的逻辑吗?
您没有限定对 name
的引用,因此它使用了它找到的唯一名为 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;
如果您实际上从 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;