Historical Rolling Daily sum

Posted by user2980057 on Stack Overflow See other posts from Stack Overflow or by user2980057
Published on 2014-06-11T15:09:23Z Indexed on 2014/06/11 15:24 UTC
Read the original article Hit count: 139

Filed under:
|
|

I have a table of consisting of Dates and the amount of revenue recorded for that day going back for about 12 years. What I would like to do with this data is create a new table with Dates and prior 7-day revenue numbers. Any guidance would be greatly appreciated. Below is an example of what my source table and what my results would need to look like....

Source Table..

DATE       |   Revenue
12/31/2013 |   200
12/30/2013 |   300
12/29/2013 |   400
12/28/2013 |   100
12/27/2013 |   200
12/26/2013 |   150
12/25/2013 |   350
12/24/2013 |   450
12/23/2013 |   200
12/22/2013 |   300
12/21/2013 |   100
12/20/2013 |   300

Resulting Table...

DATE       |   7Dayrev
12/31/2013 |    1700 
12/30/2013 |    1950
12/29/2013 |    1850
12/28/2013 |    1750
12/27/2013 |    1750
12/26/2013 |    1850
ETC......

© Stack Overflow or respective owner

Related posts about sql

Related posts about loops