Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 moving averages

Author  Topic 

GeoTom
Starting Member

5 Posts

Posted - 2011-07-14 : 18:39:15
I've got no SQL background (a little matlab and VB) but my boss has got me running the client end of our database. I haven't got a clue how to do this.

I've had a look at the other treads about this but i can't make it work. I would like to calulate a moving average of Cu_AA_pct based on 2 samples. The data is a number of different tables.

CORPSAMPLEASSAY

SAMPLEID NAME PRIORITY VAULE
01W01 Cu_AA_pct 1 1
01W01 Fe3O4_SATMAGAN_pct 1 2
01W01 P2O5_ICP_pct 1 3
01W02 Cu_AA_pct 1 4
01W02 Fe3O4_SATMAGAN_pct 1 5
01W02 P2O5_ICP_pct 1 6
01W03 Cu_AA_pct 1 7
01W03 Fe3O4_SATMAGAN_pct 1 8
01W03 P2O5_ICP_pct 1 9

the SAMPLETABLE

SAMPLEID HOLD_ID PROJECTCODE SAMPLEFROM SAMPLETO
01W01 X1 UG 10 20
01W01 X1 UG 20 30
01W01 X1 UG 30 40
01W02 X1 UG 40 50
01W02 X1 UG 50 60
01W02 Y1 UG 60 70
01W03 Y1 UG 70 80
01W03 Y1 UG 80 90
01W03 Y1 UG 90 100
01W04 C1 UG 100 110
01W04 C1 UG 110 120
01W04 C1 UG 120 130
01W05 C1 UG 130 140
01W05 C1 UG 140 150
01W05 C1 UG 150 160
01W06 C1 UG 160 170
01W06 C1 UG 170 180
01W06 C1 UG 180 190





What i would like
SAMPLEID HOLD_ID SAMPLEFROM SAMPLETO Cu_AA_pct MOVEING AVERAGE
01W01 X1 1 2 1
01W01 X1 2 3 2 1.5
01W01 X1 3 4 5 3.5
01W02 X1 4 5 6 5.5
01W02 Y1 1 1 12
01W02 Y1 2 2 24 18
01W03 Y1 3 3 1 12.5

any help would be amazzing i've been banging my head on this for most of the week.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-14 : 23:37:29
See http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=93911



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -