본문으로 바로가기
본문으로 바로가기

max

max

도입 버전: v1.1

값 그룹에서 최댓값을 계산하는 집계 함수입니다.

구문

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 │
└─────────────┴──────────────┘

비집계 max에 대한 참고 사항

-- If you need non-aggregate function to choose a maximum of two values, see greatest():
SELECT greatest(a, b) FROM table;