sql >> Base de Datos >  >> RDS >> Mysql

Consultar el próximo intervalo de tiempo

Creo que necesitas esto:

select t1.`timeto`, min(t2.`timefrom`)
from
  yourtable t1 inner join yourtable t2
  on t1.`timeto`<t2.`timefrom`
group by t1.`timeto`
having
  not exists (select null from yourtable t3
              where t1.`timeto`<t3.`timeto`
              and min(t2.`timefrom`)>t3.`timefrom`)

(esto funcionará solo si los intervalos no se superponen)