Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2002
    Posts
    10

    Unanswered: How to cumulate rows

    Hi,

    i would like to 'cumulate' row results like this

    count(*) - period_date - cumulate
    2 - 2003/07/10 - 2
    1 - 2003/07/11 - 3
    5 - 2003/07/12 - 8
    3 - 2003/07/13 - 11

    cumulate = count(*) + cumulate value of previous row

    thanks, Julien

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: How to cumulate rows

    Originally posted by gomezo
    Hi,

    i would like to 'cumulate' row results like this

    count(*) - period_date - cumulate
    2 - 2003/07/10 - 2
    1 - 2003/07/11 - 3
    5 - 2003/07/12 - 8
    3 - 2003/07/13 - 11

    cumulate = count(*) + cumulate value of previous row

    thanks, Julien
    You can use analytic functions to do this. Here's a simple example using the SCOTT.EMP table:

    Code:
    SQL> select deptno,
      2         num_emps,
      3         sum(num_emps) over (order by deptno) cum_emps
      4  from
      5  ( select deptno, count(*) num_emps
      6    from   emp
      7    group by deptno
      8* );
    
        DEPTNO   NUM_EMPS   CUM_EMPS
    ---------- ---------- ----------
            10          3          3
            20          5          8
            30          6         14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •