Run SQL below to see the solution with the same example of your question:
WITH table_(data, tempo_duracao) as (
select '01/03/2017', to_date('01/03/2017 00:45', 'DD/MM/YYYY HH24:mi') from dual union all
select '01/03/2017', to_date('01/03/2017 02:13', 'DD/MM/YYYY HH24:mi') from dual union all
select '01/03/2017', to_date('01/03/2017 00:10', 'DD/MM/YYYY HH24:mi') from dual union all
select '01/03/2017', to_date('01/03/2017 01:27', 'DD/MM/YYYY HH24:mi') from dual union all
select '02/03/2017', to_date('02/03/2017 00:23', 'DD/MM/YYYY HH24:mi') from dual union all
select '02/03/2017', to_date('02/03/2017 06:57', 'DD/MM/YYYY HH24:mi') from dual union all
select '02/03/2017', to_date('02/03/2017 00:05', 'DD/MM/YYYY HH24:mi') from dual union all
select '03/03/2017', to_date('03/03/2017 03:00', 'DD/MM/YYYY HH24:mi') from dual )
select data, numtodsinterval(sum(
SUBSTR(to_char(tempo_duracao, 'hh24:mi:ss'), 1, 2)*3600 +
SUBSTR(to_char(tempo_duracao, 'hh24:mi:ss'), 4, 2)*60 +
SUBSTR(to_char(tempo_duracao, 'hh24:mi:ss'), 7, 2)), 'SECOND')
from table_ group by data;
I’m taking into consideration that column duration has the format DATETIME
, if it’s varchar
, you may need to use the function below before using the to_char
to catch only the timestamp
:
TO_DATE(SuaDataAqui,'DD/MM/YYYY HH24:mi:ss')
References:
I have this solution in Sqlserver, but I don’t know how to convert to Oracle by not having SGDB. Basically, I sum up individually the
datepart
hours, minutes and seconds generating an undercurrent. On the outside, I use thedateadd
and we are those parts in asmalldatetime
formatting it to display only the time.– Ismael
Try to add the smallest part of the "date", seconds , convert to minutes and add the date (fraction of the day) for example 01:20 H , gives 1x60 + 20 = 80 seconds , date + ( 80 /(246060))
– Motta