sql - Moving sum over date range -
itemprop = "text">
I have this table with detailed dates and with the same value for each one of those dates, the one shown below Examples.
Date values 6/01/2013 8 6/02/2013 4 6/03/2013 1 6/04/2013 7 6/05/2013 1 6/06/2013 1 6 / 07/2013 3 6/08/2013 8 6/09/2013 4 6/10/2013 2 6/11/2013 10/6/2013 4 6/13/2013 7 6/14/2013 3 6/15 / 2013 2 6/16/2013 1 6/17/2013 7 6/18/2013 5 6/19/2013 1 6/20/2013 4
What are I trying to do I create a query that will create a new column that will display the value column for a specified date range. For example below, the sum column contains the amount of the same date of returning a full week. So the value of the date 6/9/2013 will be the sum of the values from 6/03/2013 to 6/09/2013.
Date amount 6/01/2013 8 6 / 02/2013 12 6/03/2013 13 6/04/2013 20 6/05/2013 21 6/06/2013 22 6 / 07/2013 25 6/08/2013 25/06/2013 25 6/10 / 2013 26 6/11/2013 29 6/12/2013 32 6/13/2013 38 6/14/2013 38 6/15 / 2013 32 6/16/2013 29 6/17/2013 34 6/18/2013 29 6/19/2013 26 6/20/2013 23 I use the stream of CRIP I tried it, but I could not get it to work, any help would be greatly appreciated. By using data.table
lt; - as.numeric (Ref $ Compare_Date [[1]] -x) sum ((d = -7) * Ref $ Compare_Value [[1]])}) Head (Data, 10) Date Value Roll. Val 1: 1 14 14 2: 2 7 21 3: 3 9 30 4: 4 5 35 5: 5 10 45 6: 6 10 55 7: 7 15 70 8: 8 14 84 9: 9 Requires library ("devtools") install_github ("boRingTrees", "Mgahan") (rolling tires) rolling ByCalcs (data, date = "date", target = "value", state = sum, less = 0, upper = 7)
Comments
Post a Comment