dbTalk Databases Forums  

Help: need avg(timestamp1 - timestamp2), get type error

comp.database.oracle comp.database.oracle


Discuss Help: need avg(timestamp1 - timestamp2), get type error in the comp.database.oracle forum.



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

Default Help: need avg(timestamp1 - timestamp2), get type error - 01-15-2004 , 01:30 PM






Hi -

I'm trying to query my database to find the min, max and average times
(in seconds, or minutes, or something) between two timestamps. I've
tried using:

Select avg(timestamp1 - timestamp2) from table;

I get an error saying that avg() expects a number, not an interval.
Is there a way (in a SQL stmt) to convert timestamps (or their
intervals, if they're different) so that I can run the avg, min, and
max functions?

I know that I could easily do this in C++ or Java, but I'm hoping to
do all of my calculations in SQL statements, since they will be faster
than in Java.

Thanks!
Ariant

Reply With Quote
  #2  
Old   
Jim Kennedy
 
Posts: n/a

Default Re: need avg(timestamp1 - timestamp2), get type error - 01-15-2004 , 09:05 PM







"Ariant" <ariant23 (AT) earthlink (DOT) net> wrote

Quote:
Hi -

I'm trying to query my database to find the min, max and average times
(in seconds, or minutes, or something) between two timestamps. I've
tried using:

Select avg(timestamp1 - timestamp2) from table;

I get an error saying that avg() expects a number, not an interval.
Is there a way (in a SQL stmt) to convert timestamps (or their
intervals, if they're different) so that I can run the avg, min, and
max functions?

I know that I could easily do this in C++ or Java, but I'm hoping to
do all of my calculations in SQL statements, since they will be faster
than in Java.

Thanks!
Ariant
Try the documentation. If you subtract 1 o'clock from 2 o"clock what do you
get? An interval of an hour!
Jim




Reply With Quote
  #3  
Old   
VC
 
Posts: n/a

Default Re: need avg(timestamp1 - timestamp2), get type error - 01-15-2004 , 09:42 PM



Hello,

Assuming you have a table like this:

create table t1(x timestamp, y timestamp)

... the query would be:

select avg (to_date(to_char(x, 'mm/dd/yyyy hh24:mi:ss'), 'mm/dd/yyyy
hh24:mi:ss') -
to_date(to_char(y, 'mm/dd/yyyy hh24:mi:ss'), 'mm/dd/yyyy
hh24:mi:ss')) * 24*60*60 avg_seconds
from t1


You need to convert timestamp-> char->date.


Rgds.

VC

"Ariant" <ariant23 (AT) earthlink (DOT) net> wrote

Quote:
Hi -

I'm trying to query my database to find the min, max and average times
(in seconds, or minutes, or something) between two timestamps. I've
tried using:

Select avg(timestamp1 - timestamp2) from table;

I get an error saying that avg() expects a number, not an interval.
Is there a way (in a SQL stmt) to convert timestamps (or their
intervals, if they're different) so that I can run the avg, min, and
max functions?

I know that I could easily do this in C++ or Java, but I'm hoping to
do all of my calculations in SQL statements, since they will be faster
than in Java.

Thanks!
Ariant



Reply With Quote
  #4  
Old   
Ariant
 
Posts: n/a

Default Still need avg(timestamp1 - timestamp2), get type error - 01-16-2004 , 10:47 AM



Thanks VC -

But I have one last problem, I've now realized I need microsecond
precision on my calculations (i'm using a timestamp w/ 6 decimal
places for the second). I can't seem to find a way to do that. also,
is there a way to do an "assignment" (I dont have write privleges to
the DB) so I don't have to calculate timestamp1-timestamp2 more than
once (if i want to use it a few times in a query)?

Thanks so much!
Ariant

"VC" <boston103 (AT) hotmail (DOT) com> wrote

Quote:
Hello,

Assuming you have a table like this:

create table t1(x timestamp, y timestamp)

.. the query would be:

select avg (to_date(to_char(x, 'mm/dd/yyyy hh24:mi:ss'), 'mm/dd/yyyy
hh24:mi:ss') -
to_date(to_char(y, 'mm/dd/yyyy hh24:mi:ss'), 'mm/dd/yyyy
hh24:mi:ss')) * 24*60*60 avg_seconds
from t1


You need to convert timestamp-> char->date.


Rgds.

VC

"Ariant" <ariant23 (AT) earthlink (DOT) net> wrote in message
news:7a108ec3.0401151130.25b50118 (AT) posting (DOT) google.com...
Hi -

I'm trying to query my database to find the min, max and average times
(in seconds, or minutes, or something) between two timestamps. I've
tried using:

Select avg(timestamp1 - timestamp2) from table;

I get an error saying that avg() expects a number, not an interval.
Is there a way (in a SQL stmt) to convert timestamps (or their
intervals, if they're different) so that I can run the avg, min, and
max functions?

I know that I could easily do this in C++ or Java, but I'm hoping to
do all of my calculations in SQL statements, since they will be faster
than in Java.

Thanks!
Ariant

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.