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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.0 KiB
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/argmax
2022-04-10 23:08:18 +00:00
sidebar_position: 106
2021-02-02 12:00:41 +00:00
---
# argMax {#agg-function-argmax}
计算 `val` 最大值对应的 `arg` 值。
2021-02-02 12:00:41 +00:00
2021-03-23 15:33:29 +00:00
**语法**
2021-02-02 12:00:41 +00:00
2021-03-23 15:33:29 +00:00
``` sql
argMax(arg, val)
```
**参数**
- `arg` — Argument.
- `val` — Value.
**返回值**
2021-02-02 12:00:41 +00:00
2021-03-23 15:33:29 +00:00
- `val` 最大值对应的 `arg` 值。
类型: 匹配 `arg` 类型。
**示例**
输入表:
2021-02-02 12:00:41 +00:00
``` text
┌─user─────┬─salary─┐
│ director │ 5000 │
│ manager │ 3000 │
│ worker │ 1000 │
└──────────┴────────┘
```
2021-03-23 15:33:29 +00:00
查询:
2021-02-02 12:00:41 +00:00
``` sql
2021-10-19 16:11:15 +00:00
SELECT argMax(user, salary), argMax(tuple(user, salary), salary) FROM salary;
2021-02-02 12:00:41 +00:00
```
2021-03-23 15:33:29 +00:00
结果:
2021-02-02 12:00:41 +00:00
``` text
2021-10-19 16:11:15 +00:00
┌─argMax(user, salary)─┬─argMax(tuple(user, salary), salary)─┐
│ director │ ('director',5000) │
└──────────────────────┴─────────────────────────────────────┘
2021-02-02 12:00:41 +00:00
```