Skip to main content

ImI'm trying to calccalculate the average, between a specific date/time, of the difference between the current field and the previous field. At present iveI've got a query which displays this but imI'm unsure how iI can now filter this such that iI can get the average of the 'Diff' column between a specific date/time. (Apologies in advance for my sql skill, or lack offof.)

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:

http://sqlfiddle.com/#!3/d4910/1

Im trying to calc the average, between a specific date/time, of the difference between the current field and the previous field. At present ive got a query which displays this but im 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 off)

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:

http://sqlfiddle.com/#!3/d4910/1

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:

http://sqlfiddle.com/#!3/d4910/1

Sample data
Source Link
Hans Rudel
  • 155
  • 1
  • 6

Im trying to calc the average, between a specific date/time, of the difference between the current field and the previous field. At present ive got a query which displays this but im 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 off)

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:

http://sqlfiddle.com/#!3/d4910/1

Im trying to calc the average, between a specific date/time, of the difference between the current field and the previous field. At present ive got a query which displays this but im 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 off)

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.

Im trying to calc the average, between a specific date/time, of the difference between the current field and the previous field. At present ive got a query which displays this but im 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 off)

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:

http://sqlfiddle.com/#!3/d4910/1

Source Link
Hans Rudel
  • 155
  • 1
  • 6

Average, between specific date/time, of the difference between current field and previous field

Im trying to calc the average, between a specific date/time, of the difference between the current field and the previous field. At present ive got a query which displays this but im 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 off)

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.