FOR_MAX()
function is used to search for a maximum in a specific column and return a value related to that maximum from another column.
metric
: must be one of the following data types: INT
, LONG
, FLOAT
, DOUBLE
, DATE
or TIMESTAMP
value
: can be any data type except TEXT
FOR_MAX()
function returns NULL
in the following situations:
metric
column contains only NULL
valuesvalue
corresponding to the metric minimum value is NULL
NaN
(not-a-number) if the input contains a NaN
.
payment
table that stores customer payment records, including any applied discounts:
payments
table content, run the following query:
FOR_MAX()
basic usageFOR_MAX()
with GROUP BY
clauseGROUP BY
clause to group customers and then utilise the FOR_MAX()
function to get a discount for the highest price paid by each customer: