日期:2014-05-17 浏览次数:20620 次
;with cte_tmp as (
select 1 as id, 'LN' as name, 0 as parentid, cast(null as bit) as isY
union all
select 2,'DL',1,null
union all
select 3,'GJZ',2,1
union all
select 4,'AS',1,null
union all
select 5,'TX',4,0
union all
select 6,'TD',5,1
)
select c.name,b.name,a.name,a.id
from cte_tmp a
left join cte_tmp b
on a.parentid = b.id
left join cte_tmp c
on b.parentid = c.id
where a.isY = 1