递归查询所有子节点
建人员表 hrmresource
主键 姓名 上级ID
层级关系:
- 4
- 3
- 2
- 1
- 5
- oracle
SELECT * FROM Myhrmresource
START WITH id=3
CONNECT BY PRIOR id=managerid
结果:
- sqlserver
with result_table as
(
select a.id,a.name,a.managerid from myhrmresource a where id=3
union all
select k.id,k.name,k.managerid from Myhrmresource k inner join result_table c on c.id = k.managerid
)select * from result_table
结果: