I thought this was a simple query!!!!

J

John

I have a simple table that has a date field and another
odometer reading field. I need a query to calculate the
milage difference between each of the dates. I though
this would be easy, but I'm pulling my hair out
 
K

Ken Snell [MVP]

Perhaps this will get you started (assumes that there are no duplicate dates
in the date field):

SELECT TableName.DateField, TableName.Odometer -
(SELECT TOP 1 T.Odometer FROM TableName AS T
WHERE T.DateField < TableName.DateField
ORDER BY T.DateField DESC)
FROM TableName;
 
Top