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

> 用于计算一组值中最大值的聚合函数。

# max

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

引入版本：v1.1.0

用于计算一组值中的最大值的聚合函数。

**语法**

```sql theme={null}
max(column)
```

**参数**

* `column` — 列名或表达式。[`Any`](/zh/reference/data-types)

**返回值**

组内的最大值，返回类型与输入值的类型相同。[`Any`](/zh/reference/data-types)

**示例**

**简单的 max 示例**

```sql title=Query theme={null}
CREATE TABLE employees (name String, salary UInt32) ENGINE = Memory;
INSERT INTO employees VALUES ('Alice', 3000), ('Bob', 4000), ('Charlie', 3500);

SELECT max(salary) FROM employees;
```

```response title=Response theme={null}
┌─max(salary)─┐
│        4000 │
└─────────────┘
```

**结合 GROUP BY 使用 max**

```sql title=Query theme={null}
CREATE TABLE sales (department String, revenue UInt32) ENGINE = Memory;
INSERT INTO sales VALUES ('Engineering', 100000), ('Engineering', 120000), ('Marketing', 80000), ('Marketing', 90000);

SELECT department, max(revenue) FROM sales GROUP BY department ORDER BY department;
```

```response title=Response theme={null}
┌─department──┬─max(revenue)─┐
│ Engineering │       120000 │
│ Marketing   │        90000 │
└─────────────┴──────────────┘
```

**非聚合最大值说明**

```sql title=Query theme={null}
-- 如果需要用非聚合函数取两个值中的较大值，请参阅 greatest()：
SELECT greatest(a, b) FROM table;
```

```response title=Response theme={null}
```
