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

Seleccione valores no duplicados de filas que estén separadas por menos de un número específico de minutos

-- distinct required in case there are rows with 
-- exactly the same values for datetime and number
SELECT DISTINCT a.*
FROM your_table AS a
    LEFT JOIN your_table AS b
        ON a.[number] = b.[number]
            AND a.[datetime] > b.[datetime]
            AND a.[datetime] <= DATEADD(minute, 15, b.[datetime])
WHERE b.Number IS NULL