图与递归查询技术解析
1. 祖先查询
在实际应用中,查询给定节点的祖先(即路径)是常见需求,例如返回某个员工的管理链。要实现这一功能,可以使用以下代码创建 Managers 函数:
-- Function: Managers, Ancestors with optional level limit
--
-- Input : @empid INT : Employee id
-- @maxlevels : Max number of levels to return
--
-- Output : @Mgrs Table: id and level of managers of
-- input employee in all levels <= @maxlevels
--
-- Process : * In a loop, while current manager is not null
-- and previous level is smaller than @maxlevels
-- insert into @Mgrs current manager,
-- and get next level manager
---------------------------------------------------------------------
IF OBJECT_ID(N'dbo.Managers', N'TF') IS NO
图与递归查询技术详解
超级会员免费看
订阅专栏 解锁全文
76

被折叠的 条评论
为什么被折叠?



