Calculating a rolling total??

  • Hi there

    I need to calculate a rolling total, if the table is:

    col1     col2

    1         10

    2         10

    3         15

    I need my output to be:

    col1     col2       total

    1         10          10

    2         10          20

    3         15          35

    How do I calculate the final column as a rolling total of the 2nd column?

    COMPUTE and ROLLUP is not working.

    Please help urgently.

    Thanks!

    Brenchia

     

  • Hi

    Hope, this will help:

    select T1.col1, 

     T1.col2,

     sum (T2.col2) as total

    from #Table T1 inner join #Table T2 on

     T1.col1 >= T2.col1

    group by T1.col1, T1.col2

    order by T1.col1

    Regards,

    Anna

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply