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

36 lines
944 B
Markdown
Raw Normal View History

2021-02-02 12:00:41 +00:00
---
toc_priority: 105
---
# 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
```