This should not go through the table twice, as Timβs answer.
select datediff(mi, min(x.date), max(x.date)) from ( select top(2) * from Event e order by eventNum desc ) x

Assuming that you always have 2 records or more, and the time increases monotonously, it works higher.
- If it has only one record, it returns 0 (since max = min = a special record).
- If your times are not monotonously increasing, there is a simple setting for this request
eg.
select top(1) datediff(mi, x.date, y.date) from event x join event y on y.eventnum < x.eventnum order by x.eventnum desc, y.eventnum desc
source share