#70. JOIN : 5월 식품들의 총매출 조회하기 | 프로그래머스 | SQL 고득점 Kit

문제

 

입력 코드

SELECT 
    P.PRODUCT_ID, 
    P.PRODUCT_NAME,
    SUM(O.AMOUNT * P.PRICE) AS TOTAL_SALES
FROM FOOD_PRODUCT AS P
    JOIN FOOD_ORDER AS O
    ON P.PRODUCT_ID = O.PRODUCT_ID
WHERE O.PRODUCE_DATE BETWEEN '2022-05-01' AND '2022-05-31'
GROUP BY O.PRODUCT_ID
ORDER BY TOTAL_SALES DESC, O.PRODUCT_ID ASC;

 

조건1. 생산일자가 2022년 5월인 식품

# 1. BETWEEN
WHERE O.PRODUCE_DATE BETWEEN '2022-05-01' AND '2022-05-31'

# 2. LIKE
WHERE O.PRODUCE_DATE LIKE '2022-05%'

# 3. DATE_FORMAT
WHERE DATE_FORMAT(PRODUCE_DATE, '%Y-%m') = '2022-05'

# 4. YEAR, MONTH
WHERE YEAR(PRODUCE_DATE) = 2022 AND MONTH(PRODUCE_DATE) = 5

 

 

코드 설명

#SELECT #SUM #JOIN #BETWEEN #GROUP BY #ORDER BY

 

 

문제 출처

https://school.programmers.co.kr/learn/courses/30/lessons/131117