以下查询有效:
select count(*) from everything where num not in (select num from sometable)
Run Code Online (Sandbox Code Playgroud)
以下查询应该与上面的查询等效,但会导致"无效标识符"错误:
with unwanted as (select num from sometable)
select count(*) from everything where num not in unwanted
Run Code Online (Sandbox Code Playgroud)
第二个查询有什么问题?
语法是这样的:
with unwanted as (select num from sometable)
select count(*) from everything where num not in (select * from unwanted)
Run Code Online (Sandbox Code Playgroud)
显然,只有当select num from sometable
部件稍微复杂一些或以后使用过几次时,这才有意义......