除了while loop
和Cursors
如何使用CTE表做n
块操作?
例如 :
WITH cte AS (
SELECT 1 AS n
UNION ALL
SELECT n+1
FROM cte
WHERE n+1<= 10
)
INSERT INTO tbl1 (id) select n from cte --till here it's all ok.
INSERT INTO tbl2 (id) select n from cte --{notice tbl2} .fail here ( cause cte usages must come right after the decleration)
但是,有什么我可以这样做,第二行也将包括哪些内容?
PS(旁保持它作为一个临时表)