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