- 基础数据/表结构
- Sql 语句
;With cte(id,pid,TName)As
(
Select id,pid,TName
From Test where pid = 1
Union All
Select B.id,B.pid,B.TName
From cte Inner Join Test B On cte.id = B.pid
)
select * from cte order by id
- 结果
;With cte(id,pid,TName)As
(
Select id,pid,TName
From Test where pid = 1
Union All
Select B.id,B.pid,B.TName
From cte Inner Join Test B On cte.id = B.pid
)
select * from cte order by id