I'm trying to calculate the average, between a specific date/time, of the difference between the current field and the previous field. At present I've got a query which displays this but I'm unsure how I can now filter this such that I can get the average of the 'Diff' column between a specific date/time. (Apologies in advance for my sql skill, or lack of.)
SELECT
S.Pair,
S.Date,
S.Time,
S.Bid,
S.Time,
ABS(S.Bid - T.Bid) as 'Diff'
FROM
dbo.Data as S
CROSS APPLY
(
SELECT TOP 1 T.Bid
FROM
dbo.Data as T
WHERE
T.Id > S.Id
) as T
Any pointers would be appreciated.
EDIT: