SUM, MAX, MIN

가장 비싼 상품 구하기

SELECT MAX(PRICE) AS MAX_PRICE
FROM PRODUCT

가격이 제일 비싼 식품의 정보 출력하기

SELECT PRODUCT_ID, PRODUCT_NAME, PRODUCT_CD, CATEGORY, PRICE
    FROM FOOD_PRODUCT
ORDER BY PRICE DESC LIMIT 1
SELECT * 
  FROM FOOD_PRODUCT
 WHERE PRICE IN (SELECT MAX(PRICE) 
                   FROM FOOD_PRODUCT)

최댓값 구하기

SELECT MAX(datetime) AS 시간
  FROM animal_ins
SELECT datetime AS 시간
  FROM animal_ins
ORDER BY DATETIME DESC LIMIT 1

최솟값 구하기

SELECT MIN(DATETIME) AS '시간' 
  FROM ANIMAL_INS

동물 수 구하기

SELECT MIN(DATETIME) AS '시간' 
  FROM ANIMAL_INS

중복 제거하기

SELECT COUNT(DISTINCT NAME)
  FROM ANIMAL_INS
 WHERE NAME IS NOT NULL

Last updated