A process runs (is supposed to run) every 15 mins and add and entry to a MS SQL 2012 logging table.
2013-02-07 10:07:47.000
2013-02-07 09:52:36.000
2013-02-07 09:37:34.000
2013-02-07 09:22:32.000
2013-02-07 09:07:31.000
2013-02-07 08:52:29.000
2013-02-07 08:37:28.000
2013-02-07 08:13:53.000
2013-02-07 07:58:51.000
2013-02-07 07:43:50.000
2013-02-07 07:28:48.000
2013-02-07 07:13:47.000
2013-02-07 06:58:37.000
I need help with a query that will return consecutive timestamps that are > 16 minutes apart. In the above records, the query would return 2013-02-07 08:37:28.000 and 2013-02-07 08:13:53.000
EDIT – Add reference to MS SQL
The answer to this question very much depends one which RDBMS you are using.
Something like this should work for SQL Server using
DATEDIFFandROW_NUMBER:It’s putting the dates in 2 separate columns — easy enough to put in a single column if preferred.
Here is the Fiddle.
If you let us know the RDBMS, we could put together an alternative solution if needed.
For Oracle, use
extract( minute from P2.ProcessTime - P.ProcessTime )vsDATEDIFF– the rest of the query should work — here is the Fiddle.For MySQL, the code would be a little different as MySQL doesn’t support
CTEsorROW_NUMBER. But this should get you in the right direction.Good luck.