Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

max

max

導入バージョン: v1.1.0

グループ内の値の最大値を計算する集約関数です。

構文

max(column)

引数

  • column — カラム名または式。Any

戻り値

入力と同じ型の、グループ内における最大値。Any

max の基本的な例

CREATE TABLE employees (name String, salary UInt32) ENGINE = Memory;
INSERT INTO employees VALUES ('Alice', 3000), ('Bob', 4000), ('Charlie', 3500);

SELECT max(salary) FROM employees;
┌─max(salary)─┐
│        4000 │
└─────────────┘

GROUP BY での max

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;
┌─department──┬─max(revenue)─┐
│ Engineering │       120000 │
│ Marketing   │        90000 │
└─────────────┴──────────────┘

非集計の最大値に関する注意

-- If you need non-aggregate function to choose a maximum of two values, see greatest():
SELECT greatest(a, b) FROM values('a Int32, b Int32', (1, 2), (5, 3));
┌─greatest(a, b)─┐
│              2 │
│              5 │
└────────────────┘
Navigation