--获取父类型
with c as (
select * from testtype where T_ID = 4
union all
select a.* from testtype a
join c on a.T_ID = c.ParentID
)
select top 1 * from c order by T_ID asc
--获取子类型
with c as (
select * from testtype where T_ID = 1
union all
select a.* from testtype a
join c on a.ParentID = c.T_ID
)
select * from c order by T_ID asc