while exists (
select col3 from 表
where col1 in (select id from @temp)
and col3 not in (select id from @temp)
)
insert @temp
select col3 from 表
where col1 in (select id from @temp)
and col3 not in (select id from @temp)
---把所有子节点插入@temp
select * from 表
where col3 in (select col3 from @temp)