您可以为公用表表达式创建嵌套的 WITH 子句吗?

WITH y AS (
    WITH x AS (
        SELECT * FROM MyTable
    )
    SELECT * FROM x
)
SELECT * FROM y

这样的东西有用吗?我之前尝试过,但我无法让它工作.

Does something like this work? I tried it earlier but I couldn't get it to work.

推荐答案

虽然没有严格嵌套,但您可以使用公共表表达式在后续查询中重用以前的查询.

While not strictly nested, you can use common table expressions to reuse previous queries in subsequent ones.

为此,您要查找的语句的形式是

To do this, the form of the statement you are looking for would be

WITH x AS 
(
    SELECT * FROM MyTable
), 
y AS 
(
    SELECT * FROM x
)
SELECT * FROM y

相关文章