getting values by time difference in SQL

Posted by Maestro1024 on Stack Overflow See other posts from Stack Overflow or by Maestro1024
Published on 2010-06-07T17:29:05Z Indexed on 2010/06/07 17:32 UTC
Read the original article Hit count: 165

Filed under:
|

I want to get the difference of two values within a time frame.

so I have a table like this

Data Table

TimeStamp        DataValue
2010-06-01        21
2010-06-03        33
2010-06-05        44

So I want to first get all data over the last month which I can do with something like.

([TimeStamp] < GETDATE()-0 and ([TimeStamp] > GETDATE()-31)

But I want to see how much value added on over the course of the month. So it started at 21 and went to 44. So I would expect this example to to return 23 (as in 44-21).

How would I build a query like this?

© Stack Overflow or respective owner

Related posts about sql

Related posts about query