除了 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(除了将其保留为临时表)