1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| with tab0 (Chaine,DATE_DIFF, debut, fin, ecart) as
(SELECT 'k6','2021-01-11', '14:09:14', '14:09:32', '01:07:58' union all
SELECT 'T1','2021-01-12', '14:10:51', '14:59:59', '00:01:19' union all
SELECT 'T1','2021-01-12', '15:00:00', '15:59:59', '00:00:01' union all
SELECT 'T1','2021-01-12', '16:00:00', '16:08:19', '00:00:01' union all
SELECT 'T1','2021-01-12', '16:10:27', '16:10:41', '00:02:08' union all
SELECT 'T1','2021-01-13', '17:02:37', '17:02:55', '00:00:01'
)
, tab1 (Chaine,DATE_DIFF, debut, fin, ecart, duree, maxfin) as
(SELECT T0.Chaine
, T0.DATE_DIFF
, T0.debut
, T0.fin
, timediff(T0.fin, T0.debut)
, T0.ecart
, COALESCE(T1.fin, T0.fin)
from tab0 T0 , tab0 T1
where
T1.DATE_DIFF = T0.DATE_DIFF AND T1.Chaine = T0.Chaine
and T1.fin =
(select max(fin)
from tab0
where dte=T0.DATE_DIFF
and fin > T0.fin
and ecart='00:00:01'
)
)
SELECT Chaine
, DATE_DIFF
, min(debut)
, max(fin)
, cast(sum(cast(duree as time)) as time)
from tab1
group BY Chaine, DATE_DIFF, maxfin |
Partager