MSSQL 递归查询

with     

RTD1 as(         

select * from dbo.TabName    

),     

RTD2 as(         

select * from RTD1 where id=1         

union all        

select RTD1.* from RTD2 inner join RTD1 on RTD2.id=RTD1.PID     

) 

select * from RTD2
 

 

posted @ 2018-08-30 14:29  qishidz  阅读(304)  评论(0编辑  收藏  举报