home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.oracle      Overblown overpriced overengineered SHIT      2,288 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 970 of 2,288   
   VC to Ariant   
   Re: need avg(timestamp1 - timestamp2), g   
   16 Jan 04 03:42:00   
   
   XPost: comp.database.oracle   
   From: boston103@hotmail.com   
      
   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"  wrote in message   
   news:7a108ec3.0401151130.25b50118@posting.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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca