规则是:取那些Column非0的记录的最大值为起始值.?
Column??(A OR B OR C)没看明白

解决方案 »

  1.   

    select tt1.id,tt1.ca,tt1.cb, nvl2(t1.rm,t1.rm+t1.mc,tt1.cc) cc 
    from
    tt1,
    (
    select id,ca,cb,cc,row_number() OVER (PARTITION BY ca,cb ORDER BY id) rm,(select max(t.cc) from tt1 t where t.ca = tt1.ca and t.cb = tt1.cb) mc from tt1
    where cc= 0
    ) t1
    where tt1.id = t1.id(+)
      

  2.   

    aa-> ColumnA   bb-> ColumnB   cc-> ColumnC  qwe->table name
    select  t.id,t.aa,t.bb,decode(t.cc,0,tt.cc+t.dd,t.cc) 
    from (select id,aa,bb,cc,(row_number() over(partition by aa,bb order by cc,id)) dd  from qwe) t,
         (select aa,bb,max(cc) cc from qwe group by aa,bb) tt
    where t.aa=tt.aa and
          t.bb=tt.bb
    order by id
      

  3.   

    aa-> ColumnA   bb-> ColumnB   cc-> ColumnC  qwe->table nameselect  
    -----------------------------------这个也可以
    t.id,t.aa,t.bb,decode(t.cc,0,tt.ee+tt.dd,t.cc) 
    from  qwe t,
         (select id,aa,bb,(row_number() over(partition by aa,bb order by cc,id)) dd ,
         (select max(m.cc) from qwe m where m.aa=n.aa and m.bb=n.bb group by m.aa,m.bb) ee from qwe n) tt
    where t.aa=tt.aa and
          t.bb=tt.bb and 
          t.id=tt.id
    order by id
      

  4.   

    select t.id,t.aa,t.bb,decode(t.cc,0,tt.ee+tt.dd,t.cc) 
    from  qwe t,
         (select id,aa,bb,(row_number() over(partition by aa,bb order by cc,id)) dd ,
         (select max(m.cc) from qwe m where m.aa=n.aa and m.bb=n.bb group by m.aa,m.bb) ee from qwe n) tt
    where t.aa=tt.aa and
          t.bb=tt.bb and 
          t.id=tt.id
    order by id