日期:2014-05-17 浏览次数:21253 次
with tab as
(select '10011' as ID, ' 光仔热力公司' as name, '10004' as parentid
from dual
union all
select '100013' as ID, '第三分公司' as name, '10001' as parentid
from dual
union all
select '100012' as ID, '第二分公司' as name, '10001' as parentid
from dual
union all
select '10001' as ID, '北京热力公司' as name, '0' as parentid
from dual
union all
select '10002' as ID, '上海热力公司' as name, '0' as parentid
from dual
union all
select '10004' as ID, '刘德华热力公司' as name, '0' as parentid
from dual
union all
select '100011' as ID, '第一分公司' as name, '10001' as parentid from dual)
select t1.*, t2.name as parent_name
from tab t1
left join tab t2
on t1.parentid = t2.id