Zum Inhalt springen

Aggregatfunktion.

Die Funktion MIN() gibt den Minimalwert aus einer Wertemenge zurück.

func.min(<column>)
table.station_id, func.min(table.price).alias('min_price')
| station_id | min_price |
|------------|-----------|
| 1 | 3.45 |
MIN(<expr>)
Argumente Beschreibung
<expr> Beliebiger Ausdruck

Der Minimalwert im Typ des Werts.


Aggregatfunktion.

Die Funktion MIN() gibt den Minimalwert aus einer Wertemenge zurück.

MIN(expression)
Argumente Beschreibung
expression Beliebiger Ausdruck

Der Minimalwert im Typ des Werts.

Tabelle erstellen und Beispieldaten einfügen

CREATE TABLE gas_prices (
id INT,
station_id INT,
price FLOAT
);
INSERT INTO gas_prices (id, station_id, price)
VALUES (1, 1, 3.50),
(2, 1, 3.45),
(3, 1, 3.55),
(4, 2, 3.40),
(5, 2, 3.35);

Abfragedemo: Minimalen Benzinpreis für Station 1 ermitteln

SELECT station_id, MIN(price) AS min_price
FROM gas_prices
WHERE station_id = 1
GROUP BY station_id;

Ergebnis

| station_id | min_price |
|------------|-----------|
| 1 | 3.45 |