MAX_BY

MAX_BY takes two arguments and returns the value of the first argument for which the value of the second argument is maximized. If multiple rows maximize the result of the second value, and arbitrary first value is chosen from among them. MAX_BY can be used with both numeric and non-numeric data.

ParameterTypeDescription
returned_value
any
the value to be returned, when the other argument is maximized
maximized_value
any
the value to be maximized
Returns: any

Example

query:

SELECT MAX_BY(close_date, close_value) as date_of_max_sale
  FROM sales_pipeline

result:

date_of_max_sale
2017-06-07