sql根据父id查询子项数据

查询所属id及其子项数据

with CategoryIds as
(
  select id from ProductCategory where ParentId=102 or id=102
  union all
  select a.id from ProductCategory a join CategoryIds b on a.ParentId=b.Id where a.ParentId is not null  
)
select * from ProductCategory where  id in(select id from CategoryIds)


猜你喜欢

转载自blog.csdn.net/u012394290/article/details/56840125