我有一张这样的 table
ID Title Parentid
1 Level1 0
2 Level2 1
3 Level3 2
4 Level4 1
我想根据parentid,Id关系在层次模型中输出
- 一级
- ->Level2->Level3
- -> Level4.
我能做到像
level1
/\
level2 level4.
这里我没有达到 3 级。 但我想要使用 C# 的第一个示例中所示的输出。
最佳答案
(未测试)尝试:
;with RCTE as
(select id, title full_path from MyTable where ParentID = 0
union all
select m.id, r.full_path & '->' & m.title full_path
from MyTable m, RCTE r
where m.parentid = r.id)
select full_path from RCTE
关于c# - 使用c#显示层次显示的递归函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7838173/