with subqry(id,name,parent_id) as(
select id,name,parent_id from pro_type_manage where id in ('5799936','5799946') -- start with
union all
select test1.id,test1.name,test1.parent_id from pro_type_manage as test1,subqry
where test1.parent_id = subqry.id --connect by
)
select* from subqry;
select id,name,parent_id from pro_type_manage where id in ('5799936','5799946') -- start with
union all
select test1.id,test1.name,test1.parent_id from pro_type_manage as test1,subqry
where test1.parent_id = subqry.id --connect by
)
select* from subqry;
本文提供了一个使用SQL子查询和递归查询的实际案例。通过WITH语句定义临时表,并利用递归联合全部来展示如何从指定ID开始获取所有相关记录及其层级关系。
3678

被折叠的 条评论
为什么被折叠?



