0
該查詢不起作用:CTE UNION畢竟
WITH a AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
WITH b AS
(SELECT 1 AS c1)
SELECT
*
FROM
b
你能幫忙,好嗎?
真正的查詢使用表,但它在示例中不是必需的。
非常感謝
該查詢不起作用:CTE UNION畢竟
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(一個& b)。 將WITH放入UNION查詢中會破壞UNION(因爲WITH始終在查詢之前(之前))