我试过sql server,db2,postgreSQL和Mysql.Some支持递归的基本功能,它们都不支持这样的相互递归:
WITH RECURSIVE
x (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM y WHERE id < 5),
y (id) AS (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 5)
SELECT * FROM x;
答案 0 :(得分:0)
可以:只使用second cte
(y (id)
)作为子查询
WITH
x (id) AS (SELECT 1
UNION ALL
SELECT y.id+1 FROM
(SELECT 1 id UNION ALL SELECT id+1 FROM x WHERE id < 5) y
WHERE y.id < 5)
SELECT * FROM x;
此方法适用于您提到的大多数RDBMS。 但是这些查询可能会置于无限循环。
之内