--第一题
select substr(sys_connect_by_path(t.dwdm, '->'), 3) 树形路径,
t.dwdm 本级节点号,
substr(sys_connect_by_path(t.dwbzmc, '->'), 3) 树形节点明朝,
t.dwbzmc 本级节点名称
from (select a.dwdm,
a.dwbzmc,
(case
when a.dwdm = a.ssdwbm then
null
else
a.ssdwbm
end) ssdwbm,
a.dwcc
from test1 a) t
connect by prior t.dwdm = t.ssdwbm
start with t.dwdm = '000000'
order by t.dwdm
-------------------------------------------------------------------------------------
--第2题
select a.occur_date,a.flag,sum(b.bonus_amt) from test a,test b
where a.occur_date>=20030801
and b.occur_date<=a.occur_date
and a.flag=b.flag
group by a.occur_date,a.flag;
oracle 树形结构
最新推荐文章于 2023-10-27 20:20:18 发布