MAX
Description
The MAX function is used to find the maximum value from a set of data. This function is applicable to various data types, including numeric, temporal, and string types.
Parameter Description
expr
: Comparable data types, supported types include:- Numeric types: tinyint, smallint, int, bigint, float, double, and decimal;
- Temporal types: date and timestamp;
- String types: char, varchar, string, and binary.
distinct
: Optional parameter, used to specify whether to remove duplicate values. If distinct is set, the maximum value from the deduplicated set is returned. Note that for numeric data, distinct does not affect the result.
Return Value
- The return type is the same as the input parameter
expr
. - If the input parameter contains null values, these values will not be included in the calculation.
- Setting the distinct parameter does not affect the result for numeric data.
Usage Example
- Find the maximum value of numeric data:
- Find the maximum value of time-based data:
- Find the maximum value of string type data:
- Use the distinct parameter to find the maximum value of numeric data (no effect on the result):
- Use the distinct parameter to find the maximum value of string data: