メインコンテンツへスキップ

max

導入バージョン: v1.1.0 グループ内の値の最大値を計算する集約関数です。 構文
max(column)
引数
  • column — カラム名または式。Any
戻り値 入力と同じ型の、グループ内における最大値。Any max の基本的な例
Query
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
┌─max(salary)─┐
│        4000 │
└─────────────┘
GROUP BY での max
Query
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
┌─department──┬─max(revenue)─┐
│ Engineering │       120000 │
│ Marketing   │        90000 │
└─────────────┴──────────────┘
非集計の最大値に関する注意
Query
-- 2つの値の最大値を選ぶ非集計関数が必要な場合は、greatest() を参照してください:
SELECT greatest(a, b) FROM table;
Response
最終更新日 2026年6月10日