MAX

MAX ( [ DISTINCT | ALL ] <field_expr> )

Returns the maximum value among all the values of the specified field-expression.


Arguments:

DISTINCT

Specifies that MAX returns the maximum value of unique values.
DISTINCT is not meaningful with MAX and is available for SQL-92 compatibility only.
DISTINCT can only be used when the query does not make use of the GROUP BY clause.

ALL

Applies the aggregate function to all values. ALL is the default.

<field_expr>

The field-expression among whose values the maximum is to be found.
The field-expression can be of any data type.

Return Type:

The returned type is the same as the argument field-expression.

Remarks:


Examples:

A. MAX

The following query returns the size of the largest executable file in the "system32" directory, using the FS input format:
SELECT MAX(Size)
FROM C:\windows\system32\*.*
WHERE TO_LOWERCASE(EXTRACT_EXTENSION(Name)) = 'exe'

B. MAX and GROUP BY

The following query returns the longest time spent by each page extension logged in the specified IIS W3C log file:
SELECT  TO_LOWERCASE(EXTRACT_EXTENSION(cs-uri-stem)) AS PageType,
		MAX(time-taken)
FROM ex031118.log
GROUP BY PageType

See also:

COUNT
SUM
AVG
MIN
PROPCOUNT
PROPSUM
GROUPING

Aggregate Functions

Aggregating Data Within Groups


© 2004 Microsoft Corporation. All rights reserved.