简单的SQL递归:公用查询CTE

with tmp as
(
select * from Sections where sID in
( select sItemID from LogUsersList where sID='00001' and sUsage = '预算部门')
UNION ALL
SELECT sections.* from Sections inner join tmp on sections.sID=tmp.sParent
)
SELECT distinct * FROM tmp order by sID asc

开发的预算管理系统中,用到了按人递归部门的查询。

SQL公用表达式 https://learn.microsoft.com/zh-cn/previous-versions/sql/sql-server-2008-r2/ms186243(v=sql.105)

 

posted @ 2025-09-26 09:25  海宏软件  阅读(6)  评论(0)    收藏  举报