Overview
TheFOR_MIN() function is used to search for a minimum in a specific column and return a value related to that minimum from another column.
Syntax
Arguments
metric: must be one of the following data types:INT,LONG,FLOAT,DOUBLE,DATEorTIMESTAMPvalue: can be any data type exceptTEXT
FOR_MIN() function returns NULL in the following situations:
- There are no input rows
- The
metriccolumn contains onlyNULLvalues - The
valuecorresponding to the metric minimum value isNULL
NaN (not-a-number) if the input contains a NaN.
Examples
For the needs of this section, we will use apayment table that stores customer payment records, including any applied discounts:
payments table content, run the following query:
FOR_MIN() basic usage
To determine the price associated with the lowest discount applied across all payments, use the following query:
FOR_MIN() with GROUP BY clause
To determine the discount associated with the lowest price paid by each customer, we will use the GROUP BY clause with FOR_MIN() function: