MODE
functionsupportedCore SQL functionsReturns the most frequent value for the values within expr1. NULL values are ignored. If all the values are NULL, or there are 0 rows, then the function returns NULL.
Syntax
supportedpartialnot supportednot scored
Aggregate function
MODE( <expr1> )
Window function
MODE( <expr1> ) OVER ( [ PARTITION BY <expr2> ] )
Parameters
| Name | Required | Description |
|---|---|---|
expr1 | required | This expression produces the values that are searched to find the most frequent value. The expression can be of any of the following data types: BINARY BOOLEAN DATE FLOAT INTEGER NUMBER TIMESTAMP (TIMESTAMP_LTZ, TIMESTAMP_NTZ, TIMESTAMP_TZ) VARCHAR VARIANT This function does not support the following data types: ARRAY GEOGRAPHY OBJECT |
expr2 | required | The optional expression on which to partition the data into groups. The output contains the most frequent value for each group/partition. |
Returns
The data type of the returned value is identical to the data type of the input expression.
Usage notes
- If there is a tie for most frequent value (two or more values occur as frequently as each other, and more frequently than any other value), MODE returns one of those values.
- DISTINCT is not supported for this function.
- Even if NULL is the most frequent value, the function does not return NULL (unless all values are NULL).
- When this function is called as a window function, it does not support: An ORDER BY clause within the OVER clause.
- Explicit window frames.