dbTalk Databases Forums  

Averaging a series of Times

comp.databases.sybase comp.databases.sybase


Discuss Averaging a series of Times in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chick
 
Posts: n/a

Default Averaging a series of Times - 08-11-2004 , 07:54 AM






Sorry if this is the wrong group but not sure where to post this.

I am trying to get the average time from a number of rows.

E.g
Task TimeStarted
==== =================
A 10/08/04 01:01:50
B 10/08/04 01:01:55
C 10/08/04 01:01:45

I want the Average start time for all these tasks.

The TimeStarted field is a DateTime type.

Any help gratefully received.

Reply With Quote
  #2  
Old   
Willie Kraatz
 
Posts: n/a

Default Re: Averaging a series of Times - 08-11-2004 , 12:32 PM






Run this against the sales table in pubs2 to determine if it returns the
results needed.

select dateadd (mi, avg(datediff( mi, '01/01/1900', date )), '01/01/1900' )
from sales

"Chick" <chickky1000 (AT) hotmail (DOT) com> wrote

Quote:
Sorry if this is the wrong group but not sure where to post this.

I am trying to get the average time from a number of rows.

E.g
Task TimeStarted
==== =================
A 10/08/04 01:01:50
B 10/08/04 01:01:55
C 10/08/04 01:01:45

I want the Average start time for all these tasks.

The TimeStarted field is a DateTime type.

Any help gratefully received.



Reply With Quote
  #3  
Old   
Sara Law
 
Posts: n/a

Default Re: Averaging a series of Times - 08-11-2004 , 05:36 PM



Try this Chick: Cumbersome but it seems to work. I entered your 3 rows
into a table called "times" and the result follows. Basically it
takes the minimum date in the set (at midnight) and then averages the
difference in seconds between each row in the set and the minimum date
and then adds that average to the minimum date. I displayed the
result as "varchar(26)".

select convert(varchar(26), dateadd(ss,
avg(datediff(ss,convert(datetime,
min(convert(varchar(12), TimeStarted, 112))), TimeStarted)),
convert(datetime, min(convert(varchar(12), TimeStarted,
112)))),109)
from times


Result:

--------------------------
Oct 8 2004 1:01:50:000AM


Cheers,

Sara ...

chickky1000 (AT) hotmail (DOT) com (Chick) wrote in message news:<f1037030.0408110454.5a59d5b9 (AT) posting (DOT) google.com>...
Quote:
Sorry if this is the wrong group but not sure where to post this.

I am trying to get the average time from a number of rows.

E.g
Task TimeStarted
==== =================
A 10/08/04 01:01:50
B 10/08/04 01:01:55
C 10/08/04 01:01:45

I want the Average start time for all these tasks.

The TimeStarted field is a DateTime type.

Any help gratefully received.

Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.