我正在使用oracle数据库与休眠。 我有一个EMPLOYEE表,在管理器上有一个自我链接。事情是这样的:SQL父级子级的第n级递归
create table employee(
id number(14) not null,
username varchar(100) not null unique,
manager number(14),
constraint employee_pk primary key (id),
constraint employee_manager_fk foreign key (manager) references employee (id)
);
目前,我可以选择一个员工及其直接孩子:
select e2.*
from employee e2,
(select e.* from employee e where e.username='abc') e1
where e2.manager = e1.id
union
select e.* from employee e where e.username='abc'
我想运行在那里给我可以选择的所有一个员工的用户名时,它的孩子的员工查询直到第n级。我如何在SQL语句中执行此操作?
可能重复http://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-example ) – epoch
嗯......它是相关的,但因为即使答案不同,我相信它不是重复的。 – JackDev