发布网友 发布时间:2023-06-04 10:07
共3个回答
热心网友 时间:2024-12-11 17:27
WITH lmenu(URLID,ParentID,[Level],FolderName) as ( SELECT URLID,ParentID,0 [Level],FolderName FROM tblURLFolder WHERE ParentID=0 UNION ALL SELECT A.URLID,A.ParentID,b.[Level]+1,a.FolderName FROM tblURLFolder A,lmenu b where a.ParentID = b.URLID)SELECT * from lmenu热心网友 时间:2024-12-11 17:27
一般俺喜欢用递归...SQL code ;with cte as(select * from tb where id=第一个union allselect b.* from cte a inner join tb b on a.id=b.parentid where 边界条件)select * from cte热心网友 时间:2024-12-11 17:27
参照一些递归列子http://blog.csdn.net/roy_88/article/details/2451511http://blog.csdn.net/roy_88/article/details/2045842