sqlite 使用 cte 及 遞歸的實現示例
阿新 • • 發佈:2018-05-13
實現 qlite inner font 多級 SQ cte AR sqlite
1.多級 cte 查詢示例。
with cte as ( select pageid from cm_bookpage ) , cte2 as ( select pageid, 2 as content from cte ) select * from cte2
2. cte 遞歸查詢文章標題層級,3872某一葉子節點,要查詢出所有上級目錄並排序返回。
with cte as ( select pageid,bookid,title,parentpageid,1 as orderid from cm_bookpage where pageid = 3872union all select a.pageid,a.bookid,a.title,a.parentpageid,(cte.orderid+1) as orderid from cm_bookpage a inner join cte on a.pageid = cte.parentpageid ) select * from cte order by orderid desc
sqlite 使用 cte 及 遞歸的實現示例