根节点还好弄点,要第三级的,呵呵 还好你的字段中存储了部门的层级可以简化一点 select connect_by_root(departId),connect_by_root(departName),departId from departInfo where connect_by_isleaf=1 start with departLvl>3 connect by prior parentDepartId=departId
SELECT DISTINCT departid, parentdepartid, departlvl, departname FROM departinfo di WHERE di.departlvl = 3 START WITH di.departlvl > 3 CONNECT BY PRIOR parentdepartid = departid
发现少写了个条件,呵呵 select connect_by_root(departId),connect_by_root(departName),departId from departInfo where connect_by_isleaf=1 start with departLvl>3 connect by prior parentDepartId=departId and prior departlvl>3
还好你的字段中存储了部门的层级可以简化一点
select connect_by_root(departId),connect_by_root(departName),departId
from departInfo
where connect_by_isleaf=1
start with departLvl>3
connect by prior parentDepartId=departId
SELECT DISTINCT departid, parentdepartid, departlvl, departname
FROM departinfo di
WHERE di.departlvl = 3
START WITH di.departlvl > 3
CONNECT BY PRIOR parentdepartid = departid
select connect_by_root(departId),connect_by_root(departName),departId
from departInfo
where connect_by_isleaf=1
start with departLvl>3
connect by prior parentDepartId=departId and prior departlvl>3