I need to get a list of IDs ordered by datetime from a very large table with a few million rows. This select gives a result almost instantly (a result of aprox 300 rows).
SELECT t.ID,t.Datetime from table t where (...) ORDER BY t.Datetime
As an extra field I also need the time difference of the "Datetime" field in this row and the previous row. I want to identify rows with a high time difference.
I tried joining the table with itself. The performance of these joins is very bad. What is the best approach to compare rows within a search result only?