콘텐츠로 이동

집계 함수입니다.

MAX() 함수는 값 집합에서 최댓값을 반환합니다.

func.max(<column>)
table.city, func.max(table.temperature).alias('max_temperature')
| city | max_temperature |
|------------|-----------------|
| New York | 32 |
MAX(<expr>)
인수 설명
<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 |