MAX {Expression}
The MAX function returns the largest value in the specified field.
Use MAX to calculate the largest value for a numeric, date, time, or timestamp field. As an aggregate function, MAX performs its calculation aggregating values in the same field across all rows in a dataset. The dataset can be the entire table, a filtered dataset, or a logical group produced by a GROUP BY clause. Field values of zero are included in the aggregation. NULL field values are not counted in the calculation. If the number of qualifying rows is zero, MAX returns a NULL value.
MAX function syntax has these named arguments:
Parameter |
Description |
|---|---|
Expression |
Required. The field reference or expression to return the maximum of. |
For example:
SELECT MAX(GrossAmount) FROM INHEAD
When used with a GROUP BY clause, MAX returns one calculation value for each group. This value is the aggregation of the specified field for all rows in each group. The following example aggregates the largest value for the GrossAmount field in the INHEAD table, producing a subtotal for each Customer in the ARCUST table:
SELECT C.CustomerCode , AVG(H.GrossAmount) as Average, MAX(H.GrossAmount) as Biggest, MIN(H.GrossAmount) as Smallest
FROM ARCUST C, INHEAD H
WHERE C.CustomerCode = H.CustomerCode
GROUP BY C.CustomerCode
ORDER BY C.CustomerCode