✅ 코드
SELECT P.PRODUCT_ID AS PRODUCT_ID
, P.PRODUCT_NAME AS PRODUCT_NAME
, SUM(P.PRICE * O.AMOUNT) AS SALES
FROM FOOD_PRODUCT AS P
INNER JOIN FOOD_ORDER AS O ON P.PRODUCT_ID = O.PRODUCT_ID
WHERE O.PRODUCE_DATE BETWEEN '2022-05-01 00:00:00' AND '2022-05-31 23:59:59'
GROUP BY PRODUCT_ID
ORDER BY SALES DESC
, PRODUCT_ID
INNER JOIN → 5월 생산 식품목록 필터링(WHERE) → GROUP BY 순으로 풀이가 가능합니다.
'알고리즘' 카테고리의 다른 글
[SQL]프로그래머스 Lv.4 주문량이 많은 아이스크림들 조회하기 (0) | 2024.01.16 |
---|---|
[SQL]프로그래머스 Lv.4 우유와 요거트가 담긴 장바구니 (0) | 2024.01.16 |
[SQL]해커랭크 Binary Tree Nodes (0) | 2024.01.10 |
[SQL]해커랭크 Top Competitors (0) | 2023.12.16 |
[SQL]해커랭크 The Report (0) | 2023.12.16 |