日期:2014-05-20  浏览次数:20608 次

查找根结点下的所有节点
查找根结点下的所有节点

递归的方法   怎么才能把这个节点下的   所有节点查出来


------解决方案--------------------
以下是DB2的例子
SQL code

WITH test(parentid,id,name) AS(
       VALUES
       (-1,0,'root'),
       (0,1,'----branch1'),
       (1,11,'--------branch11'),
       (11,111,'------------branch111'),
       (111,1111,'----------------branch1111'),
       (111,1112,'----------------branch1112'),
       (11,112,'------------branch112'),
       (1,12,'--------branch12'),
       (0,2,'----branch2'),
       (2,21,'--------branch21')),
       temp(parentid,id,name) AS(
       SELECT parentid,id,name FROM test WHERE name='root'
       union all
       SELECT t1.parentid,t1.id,t1.name FROM test t1,temp t2 WHERE t1.PARENTID=t2.id
       )
       SELECT name FROM temp

------解决方案--------------------
循环加递归么~