ACC: How to Compare a Field to a Field in a Prior RecordID: Q120273
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article shows you how to use a subquery to compare the values in a
record with the values in another record. In order to use the method
described in this article, the table you are using must have one or more
fields that can be compared by using the GREATER THAN (>) or LESS THAN (<)
operator.
The following example demonstrates how to calculate miles per gallon by
subtracting a recorded mileage from the current mileage, and then dividing
by the number of gallons of gasoline recorded in the current record:
Table: MileageRecord
--------------------
Field Name: Date
Data Type: Date/Time
Field Name: Mileage
Data Type: Number
Field Size: Single
Field Name: Gallons
Date Type: Number
Field Size: Double
Date Mileage Gallons
---------------------------
7/08/94 12340 14.8
7/13/94 12700 12.6
7/18/94 13090 13.7
7/25/94 13425 11.9
PrevMileage: (Select Max(Mileage) from MileageRecord _
Where Mileage < Mile1.[Mileage])
Elapsed: [Mileage] - [PrevMileage]
MPG: ([Mileage] - [PrevMileage]) / Gallons
Date Mileage PrevMileage Elapsed MPG
------------------------------------------------------------
7/08/94 12340
7/13/94 12700 12340 360 28.5714285714286
7/18/94 13090 12700 390 28.4671532846715
7/25/94 13425 13090 335 28.1512605042017
For more information about subqueries, search the Help Index for "subqueries," or ask the Microsoft Access 97 Office Assistant.
Additional query words: differential calculus
Keywords : QrySqlvw
Version : 2.0 7.0 97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 7, 1999