Declaration
ARG_MAX([DISTINCT] maximize_col, return_col)
Description
The ARG_MAX function finds the row in a dataset that maximizes a target expression and returns the value of a specified column or the entire record corresponding to that row.
Where:
maximize_colspecifies the column to maximize.return_colspecifies the column corresponding to the return value. If the value isNULL, it is skipped.
Examples
obclient> SELECT * FROM test;
+------+------+
| a | b |
+------+------+
| a | 1 |
| b | 2 |
| c | 2 |
| NULL | 3 |
| NULL | NULL |
| d | NULL |
+------+------+
6 rows in set (0.000 sec)
obclient> SELECT arg_max(a, b), max(b) FROM test;
+---------------+--------+
| arg_max(a, b) | max(b) |
+---------------+--------+
| b | 3 |
+---------------+--------+
1 row in set (0.002 sec)