JustJerry
01-30-2006, 04:37 PM
Geekgirl showed me an excellent way to perform a similar scenerio, but trying to figure out a different route.
I have a table named Mile set up as follows:
MileID Date Odometer State
1 1/1/2006 20000 MT
2 1/31/2006 25000 OR
Ok, so I have a query based on an Microsoft KB article that looks at this table and selects the previous mileage and calucates the difference. The query is based on the table Mile, with an Alias name of Mile1.
SELECT Mile1.MileID, Mile1.Date, Mile1.Odometer, Mile1.State, (Select Max(Odometer) from tblMileTotal
Where Odometer < Mile1.[Odometer]) AS PrevMileage, [Odometer]-[PrevMileage] AS Elapsed
FROM tblMileTotal AS Mile1;
So I get this from running the query:
MileID Date Odometer State PrevMileage Elapsed
1 1/1/2006 20000 MT
2 1/31/2006 25000 OR 20000 5000
Ok, here again, I can't figure out how to add to this query that looks at the 'previous state' value. So for Mile ID 2 for example, there would be a field to be called PrevState that would show MT, and so on for all the records down the line.
Is it 'SIMPLE' to add to my Select Query to bring forth the State like I can the Previous Odometer reading??
Thank you YET again
Jerry
I have a table named Mile set up as follows:
MileID Date Odometer State
1 1/1/2006 20000 MT
2 1/31/2006 25000 OR
Ok, so I have a query based on an Microsoft KB article that looks at this table and selects the previous mileage and calucates the difference. The query is based on the table Mile, with an Alias name of Mile1.
SELECT Mile1.MileID, Mile1.Date, Mile1.Odometer, Mile1.State, (Select Max(Odometer) from tblMileTotal
Where Odometer < Mile1.[Odometer]) AS PrevMileage, [Odometer]-[PrevMileage] AS Elapsed
FROM tblMileTotal AS Mile1;
So I get this from running the query:
MileID Date Odometer State PrevMileage Elapsed
1 1/1/2006 20000 MT
2 1/31/2006 25000 OR 20000 5000
Ok, here again, I can't figure out how to add to this query that looks at the 'previous state' value. So for Mile ID 2 for example, there would be a field to be called PrevState that would show MT, and so on for all the records down the line.
Is it 'SIMPLE' to add to my Select Query to bring forth the State like I can the Previous Odometer reading??
Thank you YET again
Jerry