Zum Inhalt springen

Aggregatfunktion.

Die Funktion MAX() gibt den Maximalwert aus einer Wertemenge zurück.

func.max(<column>)
table.city, func.max(table.temperature).alias('max_temperature')
| city | max_temperature |
|------------|-----------------|
| New York | 32 |
MAX(<expr>)
Argumente Beschreibung
<expr> Beliebiger Ausdruck

Der Maximalwert im Typ des Werts.

Tabelle erstellen und Beispieldaten einfügen

CREATE TABLE temperatures (
id INT,
city VARCHAR,
temperature FLOAT
);
INSERT INTO temperatures (id, city, temperature)
VALUES (1, 'New York', 30),
(2, 'New York', 28),
(3, 'New York', 32),
(4, 'Los Angeles', 25),
(5, 'Los Angeles', 27);

Abfragedemo: Maximale Temperatur für New York City ermitteln

SELECT city, MAX(temperature) AS max_temperature
FROM temperatures
WHERE city = 'New York'
GROUP BY city;

Ergebnis

| city | max_temperature |
|------------|-----------------|
| New York | 32 |