sql递归查询

--获得上级
with my as
(
select * from TB_Area where AreaID=72344566572777472
union all
select aa.* from my,TB_Area aa where my.ParentID=aa.AreaID
) select * from my
go
--获得下级
with my as
(
select * from TB_Area where AreaID=72339069014638592
union all
select aa.* from my,TB_Area aa where my.AreaID=aa.ParentID
) select * from my
原文地址:https://www.cnblogs.com/daixingqing/p/2768275.html