| Author |
Topic |
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2009-01-23 : 16:02:12
|
| for moving average for sample data of past three month from today meaning using GETDATE() how do I go about doing this following awesome SELECTSELECT DATEADD(DAY, p.ActualDate, '19000101') AS dt,AVG(p.Rate) AS SimpleMovingAvg,SUM(CASE p.dtWHEN 'dt0' THEN p.r0WHEN 'dt1' THEN p.r1WHEN 'dt2' THEN p.r2ELSE 0END) AS WeightedMovingAvgFROM (SELECT Rate,DATEDIFF(DAY, '19000101', dt) AS dt0,0.7 * Rate AS r0,DATEDIFF(DAY, '18991231', dt) AS dt1,0.2 * Rate AS r1,DATEDIFF(DAY, '18991230', dt) AS dt2,0.1 * Rate AS r2FROM @Sample) AS yUNPIVOT (ActualDateFOR dt IN (y.dt0, y.dt1, y.dt2)) AS pGROUP BY p.ActualDateHAVING MIN(p.dt) = 'dt0'ORDER BY p.ActualDateobrigadu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-24 : 12:04:35
|
| can you illustrate with some sample data? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-25 : 03:20:44
|
In your other question, I postedFROM @SampleWHERE dt >= DATEADD(MONTH, -3, GETDATE()) E 12°55'05.63"N 56°04'39.26" |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2009-01-26 : 10:17:37
|
Pesosorry to have posted new question same topic. here is the sample dataDownTimeID FromDownTimeDate ToDownTimeDate154 2008-02-18 18:10:00.000 2008-02-18 18:45:00.000446 2008-04-04 08:00:00.000 2008-04-04 08:30:00.0005 2008-01-10 20:20:00.000 2008-01-10 22:50:00.0006 2008-01-12 10:30:00.000 2008-01-12 11:00:00.000It is a DownTimeLog table with following structure..we keep logs in it for metal saws. thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-26 : 10:21:41
|
| and what should be o/p out of this? |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2009-01-26 : 10:28:02
|
| moving average for past three months.. |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2009-01-26 : 10:54:24
|
| here it is in another formarMonth Year SumMinutes10 2008 4554012 2008 76451 2009 23000 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-27 : 00:50:00
|
| what happens when downtime crosses over a month. like one from 31 dec night to 1st jan morning. you calaculate it inside dec of jan? |
 |
|
|
|