2017-08-15 46 views
0

我有这回的运行时间1200个视频下面的查询,我想总的运行时间在hh:mm:ss:ms,Postgres的查询返回的一些列值的

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

我的输出将看起来像

"00:00:33:07" 

"00:00:37:09" 

"00:01:52:02" 

"00:00:41:05" 

我试过总和(运行),但看起来我在这里做了错误的事情,

任何提示?

+3

请包括表格定义。或者在http://sqlfiddle.com/ – Gary

回答

1

一个办法 - 将它转换然后时间戳时间再到间隔,那么它会总结好了,如:

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) 

更新:在你的情况是水木清华这样的:

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'; 
+0

中设置一个测试,我将不得不手动放入1200个值,它是否可以通过像select这样的select语句加入select语句select'runtime from video where'2017-07-01'AND'2017 -07-30' ; – Jecki

+0

更新与查询从OP –

+0

完美,我需要:)谢谢Vao – Jecki