# ORDER BY 사용
SELECT PRODUCT_ID, PRODUCT_NAME, PRODUCT_CD, CATEGORY, PRICE
FROM FOOD_PRODUCT
ORDER BY PRICE DESC LIMIT 1;
# MAX 사용
SELECT *
FROM FOOD_PRODUCT
WHERE PRICE = (SELECT MAX(PRICE) FROM FOOD_PRODUCT);
# FETCH FIRST N ROWS ONLY 사용
SELECT *
FROM FOOD_PRODUCT
ORDER BY PRICE DESC
FETCH FIRST 1 ROWS ONLY;
# ORDER BY, limit
SELECT PRICE AS MAX_PRICE
FROM PRODUCT
ORDER BY PRICE DESC limit 1;
# WHERE
SELECT PRICE AS MAX_PRICE
FROM PRODUCT
WHERE PRICE = (SELECT MAX(PRICE) FROM PRODUCT);
# MAX
SELECT MAX(PRICE) AS MAX_PRICE
FROM PRODUCT;
# ORDER BY 사용
SELECT DATETIME AS 시간
FROM ANIMAL_INS
ORDER BY DATETIME DESC limit 1;
# MAX 사용
SELECT MAX(DATETIME) AS 시간
FROM ANIMAL_INS;
SELECT MIN(DATETIME) AS 시간
FROM ANIMAL_INS;
SELECT COUNT(*) as count
FROM ANIMAL_INS;
SELECT COUNT(ANIMAL_ID) as count
FROM ANIMAL_INS;
SELECT COUNT(DISTINCT(NAME))
FROM ANIMAL_INS
# WHERE NAME IS NOT NULL
# COUNT(컬럼명)은 NULL 제외하고 카운트함
'코딩테스트(Coding Test) > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 인사고과 (2) | 2024.05.01 |
---|---|
[프로그래머스] 괄호 회전하기 (1) | 2024.02.10 |
[프로그래머스.SQL] GROUP BY (0) | 2023.11.24 |
[프로그래머스/SQL] 오프라인/온라인 판매 데이터 통합하기 (0) | 2023.10.17 |