首页 > 数据库技术 > 详细

SqlServer with递归查询的使用

时间:2018-05-11 19:23:44      阅读:251      评论:0      收藏:0      [点我收藏+]

SqlServer with递归查询的使用

 

with tempAgent (AgentId,ParentId)

as(

select AgentId,ParentId from AgentInfo where AgentId=2 --要查询的根节点

union all

select a.AgentId,a.ParentId from AgentInfo a   --所有查询出所有的数据

inner join tempAgent on a.ParentId=tempAgent.AgentId --查询父节点等于Id的数据

)

 

select * from tempAgent

 

 

AgentId ParentId

2 1

7 2

8 2

9 7

SqlServer with递归查询的使用

原文:https://www.cnblogs.com/eimers/p/9025619.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!