5 sorting treeview tree ms-access parent-child
我正在努力解决排序问题。
我有一张桌子,如下所示:
aspect_id (int)
aspect_text (memo)
root_id (int) which has as a foreign key a aspect_id
Run Code Online (Sandbox Code Playgroud)
我有一个带有以下虚拟数据的非循环树:
aspect_id aspect_text root_id
1 root null
2 aspect1 1
3 aspect2 1
4 aspect3 2
5 aspect5 4
Run Code Online (Sandbox Code Playgroud)
在示例中,数据正确排序,而在我的数据库中则不然。我想对它从根元素开始进行排序,然后找到一个子代,输出该子代并递归执行。
使用CTE,这是相当可行的。Access不支持此功能。使用CTE时,将类似于:
WITH aspectTree (aspect_id, root_id, Level#) AS
(
Select
aspect.aspect_id,
aspect.root_id,
0
FROM aspect
WHERE aspect.aspect_id = 44
UNION ALL
SELECT
aspect.aspect_id,
aspect.root_id,
T.Level# + 1
FROM aspect
INNER JOIN aspectTree AS T
On T.aspect_id = aspect.root_id
)
SELECT * FROM aspectTree;
Run Code Online (Sandbox Code Playgroud)