> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 计算最小 `val` 值对应的 `arg` 和 `val` 值。如果有多行的 `val` 同为最小值，则返回哪个关联的 `arg` 和 `val` 并不确定。

# argAndMin

<div id="argAndMin">
  ## argAndMin
</div>

引入于：v1.1.0

计算最小 `val` 值对应的 `arg` 和 `val`。
如果有多行的 `val` 同为最小值，则返回其中哪一行对应的 `arg` 和 `val` 是非确定性的。
`arg` 和 `min` 这两个部分都表现为[聚合函数](/zh/reference/functions/aggregate-functions/index)：它们在处理过程中都会[跳过 `Null`](/zh/reference/functions/aggregate-functions/index#null-processing)，并且如果存在非 `Null` 值，就会返回非 `Null` 值。

<Note>
  它与 `argMin` 的唯一区别在于，`argAndMin` 同时返回参数和值。
</Note>

**另请参见**

* [argMin](/zh/reference/functions/aggregate-functions/argMin)
* [Tuple](/zh/reference/data-types/tuple)

**语法**

```sql theme={null}
argAndMin(arg, val)
```

**参数**

* `arg` — 用于查找其对应最小值的参数。[`const String`](/zh/reference/data-types/string)
* `val` — 最小值。[`(U)Int8/16/32/64`](/zh/reference/data-types/int-uint) 或 [`Float*`](/zh/reference/data-types/float) 或 [`Date`](/zh/reference/data-types/date) 或 [`DateTime`](/zh/reference/data-types/datetime) 或 [`Tuple`](/zh/reference/data-types/tuple)

**返回值**

返回一个 Tuple，其中包含与最小 `val` 值对应的 `arg` 值，以及最小 `val` 值。[`Tuple`](/zh/reference/data-types/tuple)

**示例**

**基本用法**

```sql title=Query theme={null}
SELECT argAndMin(user, salary) FROM salary;
```

```response title=Response theme={null}
┌─argAndMin(user, salary)─┐
│ ('worker',1000)         │
└─────────────────────────┘
```

**带 NULL 处理的扩展示例**

```sql title=Query theme={null}
CREATE TABLE test
(
    a Nullable(String),
    b Nullable(Int64)
)
ENGINE = Memory AS
SELECT *
FROM VALUES((NULL, 0), ('a', 1), ('b', 2), ('c', 2), (NULL, NULL), ('d', NULL));

SELECT argMin(a,b), argAndMin(a, b), min(b) FROM test;
```

```response title=Response theme={null}
┌─argMin(a, b)─┬─argAndMin(a, b)─┬─min(b)─┐
│ a            │ ('a',1)         │      0 │
└──────────────┴─────────────────┴────────┘
```

**在参数中使用 Tuple**

```sql title=Query theme={null}
SELECT argAndMin(a, (b, a)), min(tuple(b, a)) FROM test;
```

```response title=Response theme={null}
┌─argAndMin(a, (b, a))─┬─min((b, a))─┐
│ ('a',(1,'a'))        │ (0,NULL)    │
└──────────────────────┴─────────────┘
```

**另请参见**

* [argMin](/zh/reference/functions/aggregate-functions/argMin)
* [Tuple](/zh/reference/data-types/tuple)
