扩展以下问题(Multiple Select Statement)我想知道我是否可以关注:
WITH
cte1 as (
SELECT * from cdr.Location
),
cte2 as (
SELECT * from cdr.Location
WHERE cdr.Location.someField = cte1.SomeField
)
select * from cte1 union select * from cte2
这里的重点在于以下几行:
WHERE cdr.Location.someField = cte1.SomeField
在cte2中哪里我引用了cte1?
答案 0 :(得分:8)
是的,您可以在随后的CTE中引用先前声明的CTE:
WITH cte1 as (
SELECT t.*
FROM cdr.Location t),
cte2 as (
SELECT t.*
FROM cdr.Location t
JOIN cte1 c1 ON c1.somefield = t.someField)
SELECT *
FROM cte1
UNION
SELECT *
FROM cte2
备注强>