MSSQL 经典SQL 语句--WITH递归

with pb1
as (
select
c.id,
c.pid,
c.pname,
c.peopletype,
c.ptype
 from  sys_pbinstance c with(nolock)
)

,     
pb2 as
(         

select * from pb1 where id='2031ec0f-cfaa-5cbe-230c-04d1939354d3'         
union all        
select pb1.* from pb2 inner join pb1 on pb2.id=pb1.PID     

) 
select * from pb2
posted @ 2021-04-04 20:04  DavidChild  阅读(534)  评论(0编辑  收藏  举报