此查询不起作用:
WITH a AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
WITH b AS
(SELECT 1 AS c1)
SELECT
*
FROM
b
请帮忙吗?
真实查询使用表格,但在示例中并不重要。
非常感谢
答案 0 :(得分:6)
;WITH a AS
(SELECT 1 AS c1),
b AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
SELECT
*
FROM
b
答案 1 :(得分:1)
简单回答:你打破了查询; - )
让我解释一下:
所有这些的结果是您想要在UNION查询之前定义两个CTE(a& b)。 将WITH放入UNION查询会破坏UNION(因为WITH总是在查询之外(之前)。