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
'💻 하나씩 차곡차곡 > 프로그래머스 (SQL)' 카테고리의 다른 글
[JOIN/LEVEL4] FrontEnd 개발자 찾기 (MySQL) (0) | 2024.11.19 |
---|---|
[JOIN/LEVEL4] 주문량이 많은 아이스크림들 조회하기(MySQL/Oracle) (0) | 2024.11.18 |
[JOIN/LEVEL3] 있었는데요 없었습니다 (MySQL/Oracle) (1) | 2024.11.13 |
[JOIN/LEVEL2] 상품 별 오프라인 매출 구하기 (MySQL/Oracle) (0) | 2024.11.12 |
[IS NULL/LEVEL1] 잡은 물고기의 평균 길이 구하기 (MySQL) (0) | 2024.11.11 |