I have a table that keeps a running total. Every hour the new value is entered in a new record. I want to retrieve the difference between value n and n-1 in a bargraph (24 hour period). Is it possible to retrieve this information with 1 SQL statement? Or do I have to write a stored procedure for this?
If you have an integer autoincrement primary key index, you might be able to do something like this:
SELECT A.Val-B.Val FROM MyTable A JOIN MyTable B ON A.IndexCol = B.IndexCol+1
I haven’t mocked it up, but I think that should work. You’re joining the table to itself - its a handy trick for situations like this…
Hope this helps,
Worked like a charm!
Thanks a lot for the very fast, impressive and accurate response…