Syntax
ARG_MAX([DISTINCT] maximize_col, return_col)
Purpose
The ARG_MAX function is used to find the row in a dataset that maximizes the target expression and returns the value of the specified column or the full record corresponding to that row.
Where:
maximize_colis the column to be maximized.return_colis the column corresponding to the return value. IfNULL, 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)