Date/timestamp math question - Mailing list pgsql-general

From Aaron Holtz
Subject Date/timestamp math question
Date
Msg-id Pine.LNX.4.10.9904301056500.5009-100000@barbarossa.bright.net
Whole thread Raw
List pgsql-general
Hello.  I've got a timestamp field and wished to do some more advanced
math with it and haven't found examples of how to do so.  This is more an
SQL question than a postgres question, but I shall pose it anyways.
I have a table with a start and stop time.  I'd like to find the
difference between those two fields and add them up.  No problem:

db=> select sum(end_time - start_time) from data;

Now, I'd like to create a subset from that and see what % the answer is
of the above query.

db=> select sum(end_time - start_time) from data where column='Fred';

Any guesses on how I can see what percentage of the first query the
second query is (ie. How much time does Fred's query represent of the
grand total from the first query.)

My second question is how to convert the output from the first query.
If I could maybe convert the answers to seconds or hours or something else
I could do the % math within my code instead via SQL. Example:


db=> select sum(end_time - start_time) from data;
sum
--------------------------
@ 2 days 11 hours 18 mins 37 secs
(1 row)


How could I run the same query but convert it to hours only?  Basically
get this as my answer:

@ 59 hours 18 mins 37 secs


All thoughts/ideas are appreciated.

--------------------------------------------------------------------------
Aaron Holtz
ComNet Inc.
UNIX Systems Specialist
Email:  aholtz@bright.net
"It's not broken, it just lacks duct tape."
--------------------------------------------------------------------------



pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Mailing list 'relay' sites ... News servers ... WWW/FTP Mirrors
Next
From: Michael Konrad
Date:
Subject: RedHat 5.2 & PostgreSQL 6.3.2