MAX
聚合函数。
MAX() 函数返回一组值中的最大值。
语法
MAX(<expr>)
参数
返回类型
最大值,类型与该值的类型相同。
示例
Create a Table and Insert Sample Data
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);
Query Demo: Find Maximum Temperature for New York City
SELECT city, MAX(temperature) AS max_temperature
FROM temperatures
WHERE city = 'New York'
GROUP BY city;
结果
| city | max_temperature |
|------------|-----------------|
| New York | 32 |