我是 sql 新手,所以也许这是一个愚蠢的问题,但是有没有可能将 With 子句与 Insert Into 一起使用?或者有什么常见的解决方法?我的意思是这样的:
With helper_table As (
Select * From dummy2
)
Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' );
谢谢!
我的例子太假了,所以我添加了一些扩展代码(到目前为止的答案)。
INSERT
INTO dummy values (a,b) //more values
WITH helper_table AS
(
SELECT *
FROM dummy2
)
WITH helper_table2 AS //from more tables
(
SELECT *
FROM dummy3
)
SELECT t.value as a, t2.value as b
FROM helper_table t
join helper_table t2 on t.value = t2.value //some join
WHERE t.value = 'X' and t2.value = 'X' //other stuff