MAX_BY
Descriptionβ
The MAX_BY function is used to return the corresponding associated value based on the maximum value of the specified column.
Syntaxβ
MAX_BY(<expr1>, <expr2>)
Parametersβ
Parameters | Description |
---|---|
<expr1> | The expression used to specify the corresponding association. |
<expr2> | The expression used to specify the maximum value for statistics. |
Return Valueβ
Returns the same data type as the input expression
Exampleβ
select * from tbl;
+------+------+------+------+
| k1 | k2 | k3 | k4 |
+------+------+------+------+
| 0 | 3 | 2 | 100 |
| 1 | 2 | 3 | 4 |
| 4 | 3 | 2 | 1 |
| 3 | 4 | 2 | 1 |
+------+------+------+------+
select max_by(k1, k4) from tbl;
+--------------------+
| max_by(`k1`, `k4`) |
+--------------------+
| 0 |
+--------------------+