WITH L1 AS
(
SELECT
)
SELECT A FROM L1
UNION ALL
SELECT A FROM TABLE
UNION ALL
WITH L2 AS
(
SELECT
)
SELECT A FROM L2
UNION ALL
WITH L3 AS
(
SELECT
)
SELECT A FROM L3
我收到错误
关键字'with'附近的语法不正确。如果此语句是公用表表达式或xmlnamespaces子句,则必须以分号结束前一个语句。“
请帮忙
答案 0 :(得分:5)
您无法在查询表达式的中间中使用WITH
。 WITH
用于构建中间查询,以供其他查询立即使用(意味着它不能被多个独立查询使用)。
所以你可能想要这样的东西:
WITH L1
AS
(
SELECT ...
),
L2 AS
(
SELECT ...
),
L3 AS
(
SELECT ...
)
// begin final query
SELECT A FROM L1
UNION ALL
SELECT A FROM TABLE
UNION ALL
SELECT A FROM L2
UNION ALL
SELECT A FROM L3
答案 1 :(得分:3)
语法是
With l1 ( a ) as ( Select ... )
, l2 ( a ) as ( ... )
Select ... From ...
Union
Select ... From ...
答案 2 :(得分:1)
两种方法:
SELECT A FROM L1
UNION ALL
SELECT A FROM L2
UNION ALL
SELECT A FROM L3
OR
WITH CTE_L AS
(
SELECT A FROM L1
UNION ALL
SELECT A FROM L2
UNION ALL
SELECT A FROM L3
)
SELECT * FROM CTE_L