以下是CTE的示例:
declare @t table (id int, name varchar(max), parentid int)insert into @t select 1, 'project' , 0union all select 2, 'structure' , 1union all select 3, 'path_1' , 2union all select 4, 'path_2' , 2union all select 5, 'path_3' , 2union all select 6, 'path_4' , 3union all select 7, 'path_5' , 4union all select 8, 'path_6' , 5; with CteAlias as ( select id, name, parentid from @t t where t.parentid = 0 union all select t.id, parent.name + '' + t.name, t.parentid from @t t inner join CteAlias parent on t.parentid = parent.id)select * from CteAlias



