本帖最后由 chenyonge 于 2010-03-29 23:06:05 编辑

解决方案 »

  1.   

    急的话更应该认真描述清楚需求,不要让别人把时间花在推测你的意思上
    没时间的就直接略过了
    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)