💻 하나씩 차곡차곡/프로그래머스 (SQL)

[JOIN/LEVEL4] 5월 식품들의 총매출 조회하기 (MySQL/Oracle)

뚜루리 2024. 11. 15. 00:00
728x90
320x100

MySQL

SELECT    A.PRODUCT_ID
        , A.PRODUCT_NAME
        , SUM(A.PRICE * B.AMOUNT) AS TOTAL_SALES
FROM FOOD_PRODUCT A, FOOD_ORDER B
WHERE A.PRODUCT_ID = B.PRODUCT_ID
AND YEAR(PRODUCE_DATE) = 2022
AND MONTH(PRODUCE_DATE) = 5
GROUP BY A.PRODUCT_ID
,A.PRODUCT_NAME
ORDER BY TOTAL_SALES DESC, A.PRODUCT_ID

Oracle

SELECT    A.PRODUCT_ID
        , A.PRODUCT_NAME
        , SUM(A.PRICE * B.AMOUNT) AS TOTAL_SALES
FROM FOOD_PRODUCT A, FOOD_ORDER B
WHERE A.PRODUCT_ID = B.PRODUCT_ID
AND TO_CHAR(B.PRODUCE_DATE, 'YYYYMM') = '202205'
GROUP BY A.PRODUCT_ID, A.PRODUCT_NAME
ORDER BY TOTAL_SALES DESC, A.PRODUCT_ID ASC
;
728x90
320x100