--建立临时表,存储各组织直属的员工数和设备数(不建立临时表也可以,只要不嫌写一个大SQL太长) create table temp1 t as select o.Linkman, o.orgid, o.orgname, o.parentorgid, nvl(t1.emp_count), nvl(t2.equ_count) from org o, (select o1.orgid, count(*) as emp_count from org o1, emp e1 where o1.orgid = e1.orgid) t1, (select o2.orgid, count(*) as equ_count from org o2, equ e2 where o2.orgid = e2.orgid) t2 where o.orgid = t1.orgid(+) and o.orgid = t2.orgid(+) group by o.Linkman, o.orgid, o.orgname, o.parentorgid;
select t1.orgname, t1.Linkman, t1.emp_count, t1.equ_count from temp1 t1 where t1.orgid = 组织ID union select t2.orgname, t2.Linkman, t2.emp_count, t2.equ_count from temp1 t2 where t2.parentorgid = 组织ID;
------解决方案--------------------
------解决方案--------------------
一 数据量少直接 connect by start with 所求节点