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.
| Author |
Topic |
|
akholbert
Starting Member
4 Posts |
Posted - 2009-11-28 : 07:09:20
|
| I am using SQL server 2005 database.I am fairly inexperienced with SQL.I have a table containing a large amount of trend data.Starting at the first record and ending with the last record,I want to be able to process through the entire recordset taking the mean of N subsequent values and to return the calculated means as the result.This trend data is to be plotted onto a graph so execution time is an issue.Thanks in advance.AKH |
|
|
Sachin.Nand
2937 Posts |
Posted - 2009-11-28 : 10:00:23
|
| U can use the AVG function of TSQL.select AVG(yourcolumnname) from yourtable.Please post some sample data so that things will be more clear.PBUH |
 |
|
|
akholbert
Starting Member
4 Posts |
Posted - 2009-11-28 : 10:21:40
|
| ID TRENDVAL1 302 253 154 265 706 187 98 11Using the example above, how would I query this table to get the average of every n rows?i.e if n = 2I would want the following result:TRENDVAL27.5 ((30 + 25) /2)20.5 ((15 + 26) /2)44.0 ((70 + 18) /2)10.0 ((9 + 11) /2)Thanks in advance.AKH |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-11-28 : 13:38:13
|
| [code]DECLARE @n intSET @n = 2 --(as an ex.)SELECT AVG(TrendVal * 1.0)FROM(SELECT ROW_NUMBER() OVER (ORDER BY ID) AS Seq,*FROM Table)tGROUP BY (Seq-1) % @n [/code] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-28 : 13:41:44
|
quote: Originally posted by X002548You can also use centrifuges
centrifuges?biconical solid bowl screw-type centrifuge  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
akholbert
Starting Member
4 Posts |
Posted - 2009-11-28 : 15:25:23
|
| Had to replace % with /.visakh16 that worked great.Thank You for you help.AKH |
 |
|
|
|
|
|