此查询不起作用:
WITH a AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
WITH b AS
(SELECT 1 AS c1)
SELECT
*
FROM
b
你能帮忙吗?
实际查询使用表,但在示例中不是必需的。
非常感谢
此查询不起作用:
WITH a AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
WITH b AS
(SELECT 1 AS c1)
SELECT
*
FROM
b
你能帮忙吗?
实际查询使用表,但在示例中不是必需的。
非常感谢
;WITH a AS
(SELECT 1 AS c1),
b AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
SELECT
*
FROM
b
简单的答案:你打破了查询;-)
让我解释:
所有这些的结果是您希望在 UNION 查询之前定义两个 CTE(a 和 b)。将 WITH 放在 UNION 查询中会破坏 UNION(因为 WITH 总是在查询之外(之前)。