Purpose
The ARG_MIN function is used to find the row in a dataset that minimizes the target expression and returns the specified column value or the full record corresponding to that row.
Syntax
ARG_MAX([DISTINCT] minimize_col, return_col)
Parameters
| Parameter | Description |
|---|---|
minimize_col |
The column to be minimized. |
return_col |
The column corresponding to the return value, which returns the value of this column for the row with the minimum value. |
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)
