Date/timestamp math question

From: Aaron Holtz <aholtz(at)bright(dot)net>
To: pgsql-general(at)postgreSQL(dot)org
Subject: Date/timestamp math question
Date: 1999-04-30 15:06:56
Message-ID: Pine.LNX.4.10.9904301056500.5009-100000@barbarossa.bright.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)bright(dot)net
"It's not broken, it just lacks duct tape."
--------------------------------------------------------------------------

Browse pgsql-general by date

  From Date Subject
Next Message Michael Konrad 1999-04-30 18:23:58 RedHat 5.2 & PostgreSQL 6.3.2
Previous Message The Hermit Hacker 1999-04-30 15:00:03 Mailing list 'relay' sites ... News servers ... WWW/FTP Mirrors