Skip to content

Instantly share code, notes, and snippets.

@thorsman99
Created January 26, 2018 18:54
Show Gist options
  • Save thorsman99/3f39a27ba85cb18b30ee55932db075b7 to your computer and use it in GitHub Desktop.
Save thorsman99/3f39a27ba85cb18b30ee55932db075b7 to your computer and use it in GitHub Desktop.
Get average time between records #SQL
Select AVG(CAST(DATEDIFF(MINUTE,B.TimeStamp,A.TimeStamp) AS int)) AvgTime
from tblLoadPoint A
OUTER APPLY (SELECT TOP 1 *
FROM tblLoadPoint
Where TimeStamp < A.TimeStamp
Order By TimeStamp DESC) B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment