Running Sales Sum

  • I have a table

    SaleDate 1 2 3 4  5

    SalesAmount 5 6 7 8  10 

    I need a report on the running sales sum for the previous 2 days, ie.,

    for each sale date show the sum of sales for the previous  2 day period

    (3 including the current one)

    like:

    SaleDate 1 2 3 4 5

    3DaySum  5 11 18 21 25

    I have n't had much luck without using a cursor. Any work arounds?

     

  • Never mind,

    I got it.

     

    select s1.saledate, sum (s2.amount)

    from sales s1, sales  s2

    where s2.saledate between s1.saledate - 2 and s1.saledate

    group by s1.saledate

     

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

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