sql表结构中,存在Id/ParentId结构,查询指定父级的所有子级

主键:OrganizeId
父级Id:ParentId
查询父Id(db063c8c-3c4b-435b-82ca-c951f7302c3d)下所有子级记录

with cte as
(
select * from Base_Organize where ParentId='db063c8c-3c4b-435b-82ca-c951f7302c3d'
union all
select a.* from Base_Organize a join cte b on a.ParentId=b.OrganizeId
)
select * from cte

你可能感兴趣的:(SQL)