> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.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`](/ja/reference/data-types)

**戻り値**

入力と同じ型の、グループ内における最大値。[`Any`](/ja/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}
-- 2つの値の最大値を選ぶ非集計関数が必要な場合は、greatest() を参照してください:
SELECT greatest(a, b) FROM table;
```

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