17,140
社区成员




with a as(
select '01000' bao, 1 xhid, 'aaaa' th, 'zzzz' fth, 10 zq from dual
union all select '01000', 2, 'eeee', 'aaaa', 10 from dual
union all select '01000', 3, 'iiii', 'eeee', 30 from dual
union all select '01000', 4, 'zzzz', 'iiii', 18 from dual),
b as(
select '01000' bao,'aaaa' th,date'2010-5-1' jstime from dual)
select bao,
xhid,
th,
fth,
jstime - days starttime,
jstime - days + zq endtime
from (select a.*,
sum(a.zq) over(partition by rownum - level order by level) days,
b.jstime
from a, b
where a.bao = b.bao
start with b.th = a.th
connect by nocycle prior a.fth = a.th
and prior a.bao = b.bao)