create table if not exists testtable( ID INT PRIMARY KEY,[name] NVARCHAR(20),parentID INT );INSERT INTO testtable(ID,[name],parentID) VALUES(1,'xf1',0);INSERT INTO testtable(ID,parentID) VALUES(2,'xf2',parentID) VALUES(3,'xf3',2);INSERT INTO testtable(ID,parentID) VALUES(4,'xf4',3);INSERT INTO testtable(ID,parentID) VALUES(5,'xf5',4);INSERT INTO testtable(ID,parentID) VALUES(6,'xf6',5);WITH RECURSIVE cte(ID,name,parentID) AS( SELECT ID,parentID FROM testtable WHERE ID='6' UNION ALL SELECT a.ID,a.name,a.parentID FROM testtable AS a INNER JOIN cte ON a.ID=cte.parentID )SELECT * FROM cte;
--得到1-10 的数WITH RECURSIVE cnt(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM cnt WHERE x<10)SELECT x FROM cnt order by x;WITH RECURSIVE cnt(x) AS ( SELECT 1 UNION ALL SELECT x+1 FROM cnt liMIT 10 )SELECT x FROM cnt order by x;
参考:点击打开链接
总结以上是内存溢出为你收集整理的SQLite 中的递归全部内容,希望文章能够帮你解决SQLite 中的递归所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)