sqlserver查询树形结构的所有子节点 20
1个回答
2017-08-23
展开全部
sqlserver查询树形结构的所有子节点
用标准sql的with实现递归查询(sql2005以上肯定支持,sql2000不清楚是否支持):
with subqry(id,name,pid) as (
select id,name,pid from test1 where id = 5
union all
select test1.id,test1.name,test1.pid from test1,subqry
where test1.pid = subqry.id
)
select * from subqry;
用标准sql的with实现递归查询(sql2005以上肯定支持,sql2000不清楚是否支持):
with subqry(id,name,pid) as (
select id,name,pid from test1 where id = 5
union all
select test1.id,test1.name,test1.pid from test1,subqry
where test1.pid = subqry.id
)
select * from subqry;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |