select id
, value
, floor(value / 86400) as days
, floor(mod(value, 86400) / 3600) as hours
, floor(mod(value, 3600) / 60) as mins
, mod(value, 60) as secs
from your_table
-- test table: NUMBERS
create table numbers ( id_, value_ ) as
select '001', 125698 from dual union all
select '002', 5698233 from dual union all
select '001', 896398233 from dual ;
我想对ID 001的值求和并转换为dd:hh:mm:ss
select
numtodsinterval( sum( value_ ), 'second' )
from numbers
where id_ = '001'
;
-- result
NUMTODSINTERVAL(SUM(VALUE_),'SECOND')
+10376 10:25:31.000000
2 回答
不幸的是,没有一些简单的方法来推导它 . 但是,我们可以通过混合使用
floor()
和mod()
来计算天数,小时数,分钟数和秒数,如下所示:也许你发现NUMTODSINTERVAL函数很有用 . 示例(Oracle 11g)
您可以EXTRACT结果的天/小时/分钟/秒,并使用连接运算符添加一些':'字符 .
另见:dbfiddle