Quantcast
Channel: Rolling SUM with a 30 day range - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 2

Rolling SUM with a 30 day range

0
0

I am using SQL Server 2012 and have a db with around 2 million rows. I need to figure out how to calculate a rolling sum over a 30 day range and return any results over a set amount (amt_pur). These are transaction orders so the id number (ID_NO) is the same but transaction date(TD) varies by minutes to many years at times. So if a customer ordered 10 items within any 30 day period I need those results. I tried something like this and many googled variations:

select id_no, td, sum(amt_pur) as amtpur from db1 where td between td and dateadd(day,30,td)group by id_no, td, amt_pur having sum(amt_pur)>10 order by amtpur desc

This does not get me rolling type calculation results. I have a specific ID I can verify this with so I know I'm not getting the right ones. Please help!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images