Declaration
ARG_MAX([DISTINCT] minimize_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 for that row.
Where:
minimize_colspecifies the column to minimize.return_colspecifies the column corresponding to the return value. It returns the value of this column for the row with the minimum value. If a row containsNULL, it is ignored.
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_min(a, b), min(b) FROM test;
+---------------+--------+
| arg_min(a, b) | min(b) |
+---------------+--------+
| a | 1 |
+---------------+--------+
1 row in set (0.006 sec)