我在这里找到了一个有趣的递归查询(http://beyondrelational.com/modules/2/blogs/28/posts/10486/recursive-cte-and-ordering-of-the-hierarchical-result.aspx)并且我适应了我的需求,但是没有用。
以下是代码:
WITH cte AS (
SELECT 0 AS lvl, collectionID, collectionName, parentCollectionID, CAST(collectionID AS VARCHAR(128)) AS Sort
FROM collections WHERE parentCollectionID IS NULL
UNION ALL
SELECT p.lvl + 1, c.collectionID, c.collectionName, c.parentCollectionID, CAST(p.Sort + '/' + CAST(c.collectionID AS VARCHAR) AS VARCHAR(128))
FROM collections c
INNER JOIN cte p ON p.collectionID = c.parentCollectionID
)
SELECT
collectionID,
SPACE(lvl * 4) + collectionName AS collectionName,
Sort,
parentCollectionID
FROM cte ORDER BY Sort;
我收到此消息:“内核错误:靠近”WITH“:语法错误”
拜托,我要做些什么来解决它? 我正在使用SQLIte 3.8.2