DONET-LC
 with temp(id,name,curlevel,hasChild)
 as 
 (
 --初始查询
 select id,name,1 curlevel,1 hasChild from tabName pc with(nolock)
 where Disabled = 0 and ParentId is null
 union all
 --查询子语句
 select pchild.id id,pchild.name name,p.curlevel +1 curlevel,
 (case when exists(select 1 from tabName where ParentId = pchild.id) then 1 else 0 end) hasChild 
 from tabName pchild with(nolock) 
 inner join temp p on pchild.ParentId = p.id and pchild.Disabled = 0
 )
 select * from temp

  

分类:

技术点:

相关文章:

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