yanglang

例如:找ProductType表 下ID为1的分类的所有子级

with result as    --result为别名

select * from TB_ProductType where Id=1  --查询ID为1 的数据
union all 
select TB_ProductType.* from tb_productType, result where result.ID = TB_ProductType.ParentID  ---递归--找到ID为1的分类的所有下级

 select * from result  --注意 上面只是获取了递归的对象 所以这里必须要查询一次

 

--递归删除  / 更新

with result as 

select * from TB_ProductType where Id=1 
union all 
select TB_ProductType.* from tb_productType, result where result.ID = TB_ProductType.ParentID

update TB_ProductType set name = \'\' where id in ( select id from result)  -- 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-07-24
猜你喜欢
  • 2021-12-26
  • 2021-12-09
相关资源
相似解决方案