sql >> Base de Datos >  >> RDS >> Sqlserver

Alternativa de la función de retraso de avance en SQL Server 2008

En tu caso, el id s parecen ser numéricos, solo puede hacer una autounión:

select t.*
from table t join
     table tnext
     on t.id = tnext.id - 1 and
        t.StatusId = 1 and
        tnext.StatusId = 6 and
        datediff(second, t.MinStartTime, tnext.MinStartTime) < 60;

Este no es exactamente el mismo minuto. Es dentro de los 60 segundos. ¿Realmente necesita el mismo minuto de tiempo de calendario? Si es así, puedes hacer:

select t.*
from table t join
     table tnext
     on t.id = tnext.id - 1 and
        t.StatusId = 1 and
        tnext.StatusId = 6 and
        datediff(second, t.MinStartTime, tnext.MinStartTime) < 60 and
        datepart(minute, t.MinStartTime) = datepart(minute, tnext.MinStartTime);