postgres查询返回一些列值

时间:2017-08-15 07:19:08

标签: sql postgresql casting

我的以下查询返回了1200个视频的运行时间,我希望获得hh:mm:ss:ms

的总运行时间
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"

我已经尝试了总和(运行时),但看起来我在这里做错了,

任何提示?

1 个答案:

答案 0 :(得分: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';