我写了一个,在Oracle8i中测试通过:select a.ActDate 日期, a.ActCount 数量,a.ActCount+ (select nvl(max(ActCount),0) from test b where b.ActDate<a.ActDate) 累计数量 
from test a

解决方案 »

  1.   

    笔误,更正如下:
    select a.ActDate 日期, a.ActCount 数量,a.ActCount+ (select nvl(sum(ActCount),0) from test b where b.ActDate<a.ActDate) 累计数量 
    from test a
      

  2.   

    直接sum()就可以啊select actdate 日期, actcount 数量, (select sum(actcount) from yourtable b where b.actdate <= a.actdate) 累计数量
    from yourtable a
      

  3.   

    select actdate 日期, actcount 数量, (select sum(actcount) from yourtable b where b.actdate <= a.actdate) 累计数量
    from yourtable a
      

  4.   

    SQL> select a.BIRTHDAY 日期, a.id 数量, (select sum(id) from student b where b.BIRTHDAY <= a.BIRTHDA
    Y) 累计数量 from student a order by BIRTHDAY;日期             数量   累计数量
    ---------- ---------- ----------
    19-12月-02         10         10
    20-12月-02         20         30
    21-12月-02         30         60
    22-12月-02         40        100
      

  5.   

    create or replace function get(p_date in date) 
    return number 
    is 
    cursor v_cursor(v_date date) is
            select sum(id) id from student where BIRTHDAY <=v_date ;
         records number:=0;
       begin
         for v_val in v_cursor(p_date)
         loop
         
         records:=records+v_val.id;
        end loop; 
        return(records);
    end get;
    /SQL> select BIRTHDAY 日期, id 数量, get(birthday) 累计数量 from student  order by BIRTHDAY;日期             数量   累计数量
    ---------- ---------- ----------
    19-12月-02         10         10
    20-12月-02         20         30
    21-12月-02         30         60
    22-12月-02         40        100
      

  6.   

    谢谢各位兄弟,特别是饿着肚子的 beckhambobo(beckham)