相关疑难解决方法(0)

在递归公用表表达式中使用 EXCEPT

为什么以下查询返回无限行?我本来希望该EXCEPT条款终止递归..

with cte as (
    select *
    from (
        values(1),(2),(3),(4),(5)
    ) v (a)
)
,r as (
    select a
    from cte
    where a in (1,2,3)
    union all
    select a
    from (
        select a
        from cte
        except
        select a
        from r
    ) x
)
select a
from r
Run Code Online (Sandbox Code Playgroud)

我在尝试回答Stack Overflow 上的一个问题时遇到了这个问题

sql-server-2008 sql-server execution-plan recursive except

33
推荐指数
2
解决办法
1万
查看次数