简单的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)

浙公网安备 33010602011771号