我试图将NOT IN与T-SQL中的WITH组合在一起。但是无法让它发挥作用。可能吗?
示例:
select name
from Persons
where id NOT IN
(
WITH result (numbers)
AS
(
select number from num
)
select numbers from result
)
答案 0 :(得分:4)
WITH
关键字不能在子查询中使用,它必须在主查询之前。
WITH result (numbers)
AS
(
select number from num
)
select name
from Persons
where id NOT IN
(
select numbers from result
)
答案 1 :(得分:0)
我知道你已经得到了答案,但是如果有人对未来感兴趣的话,只想展示解决问题的替代方法。
SELECT name
FROM Persons
WHERE id NOT IN (select number from num)