SQL Reference
...
SQL Functions
Aggregation Functions
FOR_MAX
7min
FOR_MAX() function takes two arguments: metric and value. Returns a value corresponding to the maximum metric in the same row from a set of values.
The value argument can be one of the following types:
- INT
- LONG
- FLOAT
- DOUBLE
- DATE
- TIMESTAMP
The value argument can be of any type except STRING.
š”Special cases:
- Returns NULL if:
- there are no input rows
- the metric column has only NULL values
- the value corresponding to the maximum metric is NULL.
- Returns NaN if the input contains a NaN.
We have a payments table that stores the records of payments by customers, along with discounts applied during the payment:


It will create a table as shown below:

For example, let's check the price for the highest discount applied to it:

It will return the following output (NULL in this case):

For this example, we use a GROUP BY clause to group the customers, then use FOR_MAX() to get a discount for the highest price paid by each customer.

Which will give the following result: