The <value> from the row with the maximum <key> among considered rows.
Null handling:
You can combine max_by with other aggregates, GROUP BY, HAVING, subqueries, and expressions in the arguments (for example, max_by(upper(name), score * 2)).
max_by only supports a single value to sort on. To sort using multiple sort criteria, use FIRST_VALUE WITHIN GROUP.
If the aggregate has no input rows (empty table or empty group), the result is NULL.
If every row has a NULL key, those rows are skipped; if no row has a non-NULL key, the result is NULL.
If the winning row’s <value> is NULL, the result is NULL (the key still determines which row wins).
Tie-breaking: If multiple rows share the same maximum key, one of the tied <value> results is returned; which tied row wins is implementation-dependent.
Considerations
DISTINCT is not supported (for example, max_by(DISTINCT name, score) is a syntax error).
Rows with a NULL<key> are ignored when searching for the maximum key.
You can combine max_by with other aggregates, GROUP BY, HAVING, subqueries, and expressions in the arguments (for example, max_by(upper(name), score * 2)).
Examples
Top scorer by score
Returns the name and score from the row with the highest score.