SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 27th, 2004, 04:09 PM
MiaWie MiaWie is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 MiaWie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question How to get a sliding average value for periodic stored values.

Hi experts,



you are nearly my last chance to solve a sql problem. I hope that someone can help me.



Keywords: average, time offset, data period



I want to get data from a database in Excel to calculate a mathematic model. The problem is, that the model requires averaged data. I have 26 variables, which are stored every 10 seconds. What I would like to get is a sliding average value with 5 minutes before and five minutes after a specific time.





+---------------------+---------+-------------

| DateTime | Value 1 | Avg(Value1)

|---------------------+---------+-------------

|3/14/2003 2:55:00 PM | 856 | 850

|3/14/2003 2:56:00 PM | 850 | 851

|3/14/2003 2:57:00 PM | 852 | 851

|3/14/2003 2:58:00 PM | 600 | 850

|3/14/2003 2:59:00 PM | 860 | 849

|3/14/2003 3:00:00 PM | 854 | 850

|3/14/2003 3:01:00 PM | 850 | 850

|3/14/2003 3:02:00 PM | 849 | 849

|3/14/2003 3:03:00 PM | 865 | 850

|3/14/2003 3:04:00 PM | 851 | 850

|3/14/2003 3:05:00 PM | 849 | 850

|3/14/2003 3:06:00 PM | 855 | 851





What I have now is:



SELECT

CONVERT(VARCHAR(10), DateTime, 110) + ' ' + CONVERT(VARCHAR(2), DateTime, 108) + ':' + CONVERT(VARCHAR(2), FLOOR(DATEPART(mi, DateTime) / 5) * 5) AS 'Five Minute Period Starting',

TagName,

AVG(Value) AS 'Average'

FROM Runtime..AnalogHistory

WHERE

TagName IN ('Variable1', 'Varable2', 'Variable3') AND

DateTime >= '3/14/2003 2:55' AND

DateTime < '3/17/2003 11:00' AND

wwRetrievalMode = 'DELTA'

GROUP BY

CONVERT(VARCHAR(10), DateTime, 110) + ' ' + CONVERT(VARCHAR(2), DateTime, 108) + ':' + CONVERT(VARCHAR(2), FLOOR(DATEPART(mi, DateTime) / 5) * 5),

TagName



With this code I can get the average from the values in a five minute data period. This code doesn’t calculate a sliding average. But I need a sliding average to set a time offset or to get data period from, for example, an average value every two minutes.



I’m not sure if I’m describing my problem clearly.



Thanks a lot for your help in advance.



Best regards



Melanie






Reply With Quote
  #2  
Old May 28th, 2004, 11:20 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
You will need something similar to this



Select DateTime, Value, (Select Avg(Value) from Table1 Where Table1.DateTime between (t.DateTime +5 min) and t.DateTime - 5 min)) as 'Average' From Table1 as T

S-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > How to get a sliding average value for periodic stored values.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT