oracle 计算 小时 分钟 秒
请问oracle 如何计算出时间差的 小时 分钟 秒 比如:表里有两列
2013-01-11 09:03:20 2013-01-11 10:08:29 相差1小时5分钟9秒
2013-01-12 09:03:20 2013-01-14 10:04:21 相差48小时
2013-01-15 15:24:02 2013-01-15 17:20:57 相差1小时56分55秒
统计出来的是: 51:02:04 ? 请指点!!!
[解决办法]
1天 24小时
1小时 60分钟
1分钟 60秒
自己动手算啊 ,就像二进制十进制一样,不要什么东西都问
[解决办法]
with test as (
select '2013-01-11 09:03:20' as st,'2013-01-11 10:08:29' as et from dual
union all
select '2013-01-12 09:03:20' as st,'2013-01-14 10:04:21' as et from dual
union all
select '2013-01-15 15:24:02' as st,'2013-01-15 17:20:57' as et from dual
)
SELECT TRUNC(sum(CT) / 3600, 0)
[解决办法]
':'
[解决办法]
TRUNC(MOD(sum(CT), 3600) / 60, 0)
[解决办法]
':'
[解决办法]
MOD(sum(CT), 60) AS TT
FROM (select (to_char(to_date(et, 'yyyy-mm-dd hh24:mi:ss'), 'dd') * 24 * 60 * 60 +
to_char(to_date(et, 'yyyy-mm-dd hh24:mi:ss'), 'hh24') * 60 * 60 +
to_char(to_date(et, 'yyyy-mm-dd hh24:mi:ss'), 'mi') * 60 +
to_char(to_date(et, 'yyyy-mm-dd hh24:mi:ss'), 'ss')) -
(to_char(to_date(st, 'yyyy-mm-dd hh24:mi:ss'), 'dd') * 24 * 60 * 60 +
to_char(to_date(st, 'yyyy-mm-dd hh24:mi:ss'), 'hh24') * 60 * 60 +
to_char(to_date(st, 'yyyy-mm-dd hh24:mi:ss'), 'mi') * 60 +
to_char(to_date(st, 'yyyy-mm-dd hh24:mi:ss'), 'ss')) as CT
from test)
[解决办法]
with test as (
select '2013-01-11 09:03:20' as st,'2013-01-11 10:08:29' as et from dual
union all
select '2013-01-12 09:03:20' as st,'2013-01-14 10:04:21' as et from dual
union all
select '2013-01-15 15:24:02' as st,'2013-01-15 17:20:57' as et from dual
)
select trim(to_char(trunc(dif_time / 3600), '09'))
------解决方案--------------------
':'
[解决办法]
trim(to_char(trunc(mod(dif_time, 3600) / 60), '09'))
[解决办法]
':'
[解决办法]
trim(to_char(mod(dif_time, 60), '09')) as sum_dif_time
from (select sum((to_date(et, 'yyyy-mm-dd hh24:mi:ss') -
to_date(st, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 * 60) as dif_time
from test)
select trunc(&second/3600) as hours,trunc(mod(&second,3600)/60) as minutes,mod(&second,60) as seconds from dual;