ClickHouse/docs/zh/sql-reference/aggregate-functions/reference/argmin.md

37 lines
1009 B
Markdown
Raw Normal View History

2021-02-02 12:00:41 +00:00
---
2022-08-26 19:07:59 +00:00
slug: /zh/sql-reference/aggregate-functions/reference/argmin
2022-04-10 23:08:18 +00:00
sidebar_position: 105
2021-02-02 12:00:41 +00:00
---
# argMin {#agg-function-argmin}
语法: `argMin(arg, val)``argMin(tuple(arg, val))`
计算 `val` 最小值对应的 `arg` 值。 如果 `val` 最小值存在几个不同的 `arg` 值,输出遇到的第一个(`arg`)值。
**示例:**
2021-03-24 15:46:03 +00:00
输入表:
2021-02-02 12:00:41 +00:00
``` text
┌─user─────┬─salary─┐
│ director │ 5000 │
│ manager │ 3000 │
│ worker │ 1000 │
└──────────┴────────┘
```
2021-03-24 15:46:03 +00:00
查询:
2021-02-02 12:00:41 +00:00
``` sql
2021-10-19 16:14:14 +00:00
SELECT argMin(user, salary), argMin(tuple(user, salary), salary) FROM salary;
2021-02-02 12:00:41 +00:00
```
2021-03-24 15:46:03 +00:00
结果:
2021-02-02 12:00:41 +00:00
``` text
2021-10-19 16:14:14 +00:00
┌─argMin(user, salary)─┬─argMin(tuple(user, salary), salary)─┐
│ worker │ ('worker',1000) │
└──────────────────────┴─────────────────────────────────────┘
2021-02-02 12:00:41 +00:00
```