我的以下查询返回了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"
我已经尝试了总和(运行时),但看起来我在这里做错了,
任何提示?
答案 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';