5,889
社区成员
发帖
与我相关
我的任务
分享
create table tst (
id integer,
parentId int,
name varchar(20))
insert into tst values
(1,0,'a'),
(2,0,'b'),
(3,1,'c'),
(4,1,'d'),
(5,4,'d'),
(6,5,'d')
with rpl (id,parentId,name) as
(
select id,parentId,name from tst where parentId=1
union all
select child.id,child.parentId,child.name from rpl parent, tst child where parent.id=child.parentId
)
select * from rpl