MAX
集計関数。
MAX() 関数は、値の集合の中から最大値を返します。
構文
MAX(<expr>)
引数
戻り値の型
値の型における最大値を返します。
例
テーブルを作成してサンプルデータを挿入する
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);
クエリのデモ: ニューヨーク市の最高気温を検索する
SELECT city, MAX(temperature) AS max_temperature
FROM temperatures
WHERE city = 'New York'
GROUP BY city;
結果
| city | max_temperature |
|------------|-----------------|
| New York | 32 |