0

I've the following query which return the run time for 1200 videos , i want to get the total of run time in hh:mm:ss:ms

select  runtime from video where ready_date between '2017-07-01' AND '2017-07-30';

my output will look like

"00:00:33:07"

"00:00:37:09"

"00:01:52:02"

"00:00:41:05"

i've tried sum(runtime) but looks i'm doing the wrong thing here ,

any tips ?

1
  • 3
    Please include the table definition. Alternatively set up a test in sqlfiddle.com Commented Aug 15, 2017 at 7:29

1 Answer 1

1

one way - cast it to timestamp then to time then to interval, then it will sum up ok, eg:

vao=# with video(runtime) as (values('00:00:33:07'),('00:00:37:09'),('00:01:52:02'))
select sum(to_timestamp(runtime,'HH24:MI:ss:ms')::time::interval) from video;
     sum
-------------
 00:03:02.18
(1 row)

update: In your case would be smth like:

select sum(to_timestamp(runtime::text,'HH24:MI:ss:ms')::time::interval) 
from video 
where ready_date between '2017-07-01' AND '2017-07-30';
Sign up to request clarification or add additional context in comments.

2 Comments

i'll have to put 1200 values manully , can it join by select statement like this select runtime from video where ready_date between '2017-07-01' AND '2017-07-30';
Perfect , all i need :) Thank Vao

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.