Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

max

max

Introduzido em: v1.1.0

Função de agregação que calcula o valor máximo em um grupo de valores.

Sintaxe

max(column)

Argumentos

  • column — Nome da coluna ou expressão. Any

Valor retornado

O valor máximo do grupo, com tipo igual ao da entrada. Any

Exemplos

Exemplo simples de 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 │
└─────────────┘

Max com GROUP BY

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

Observação sobre o máximo sem agregação

-- 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