Use the string expression argument in an SQL aggregate function to perform a calculation on values in a field. For example, you could calculate a percentage (such as a surcharge or sales tax) by multiplying a field value by a fraction.
The following table provides examples of calculations on fields from the Orders and Order Details tables in the Northwind.mdb database.
Calculation | Example |
Add a number to a field |
|
Subtract a number from a field |
|
Multiply a field by a number |
|
Divide a field by a number |
|
Add one field to another |
|
Subtract one field from another |
|
The following example calculates the average discount amount of all orders in the Northwind.mdb database. It multiplies the values in the UnitPrice and Discount fields to determine the discount amount of each order and then calculates the average. You can use this expression in an SQL statement in Visual Basic code:
SELECT Avg(UnitPrice * Discount) AS [Average Discount] FROM [Order Details];