2015-04-12 73 views
2

我已經嘗試的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

有可能:只使用second ctey (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。 但這樣的查詢可能會放入一個無限循環

相關問題