Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql-不与组合在一起_Sql_Sql Server - Fatal编程技术网

Sql-不与组合在一起

Sql-不与组合在一起,sql,sql-server,Sql,Sql Server,我正在尝试将notin与T-SQL结合起来。但无法让它工作。可能吗 例如: select name from Persons where id NOT IN ( WITH result (numbers) AS ( select number from num ) select numbers from result ) WITH关键字不能在子查询

我正在尝试将notin与T-SQL结合起来。但无法让它工作。可能吗

例如:

    select name 
    from Persons
    where id NOT IN 
    (
        WITH result (numbers)
        AS
        (
            select number from num
        )
        select numbers from result
    )
WITH关键字不能在子查询中使用,它必须在主查询之前

WITH result (numbers)
AS
(
    select number from num
)
select name 
from Persons
where id NOT IN 
(
    select numbers from result
)
WITH关键字不能在子查询中使用,它必须在主查询之前

WITH result (numbers)
AS
(
    select number from num
)
select name 
from Persons
where id NOT IN 
(
    select numbers from result
)

我知道你已经得到了答案,但是如果有人对未来感兴趣的话,我只是想展示解决这个问题的另一种方法

SELECT name 
FROM Persons
WHERE id NOT IN (select number from num)

我知道你已经得到了答案,但是如果有人对未来感兴趣的话,我只是想展示解决这个问题的另一种方法

SELECT name 
FROM Persons
WHERE id NOT IN (select number from num)

对于许多人来说,当返回NULL时结果不一致是有点令人惊讶的。这就是为什么我通常建议使用NOT EXISTS来代替。这是一种练习,还是你可以应用一种更简单的方法?为什么你要使用WITH???因为在WITH子句中,我选择了我们分组并重新选择的多重连接查询中的数据。返回NULL时结果不存在,这让很多人有点惊讶。这就是为什么我通常建议使用NOT EXISTS来代替。这是一种练习,还是可以应用一种更简单的方法?为什么要使用WITH???因为在WITH子句中,我在我们分组并重新选择的多连接查询中选择数据。