💻 하나씩 차곡차곡/프로그래머스 (SQL)
[JOIN/LEVEL2] 상품 별 오프라인 매출 구하기 (MySQL/Oracle)
뚜루리
2024. 11. 12. 00:00
728x90
320x100
MySQL/Oracle
SELECT A.PRODUCT_CODE
, A.PRICE * B.SALES_AMOUNT AS SALES
FROM PRODUCT A, (SELECT PRODUCT_ID
, SUM(SALES_AMOUNT) AS SALES_AMOUNT
FROM OFFLINE_SALE
GROUP BY PRODUCT_ID) B
WHERE A.PRODUCT_ID = B.PRODUCT_ID
ORDER BY SALES DESC, PRODUCT_CODE
SELECT A.PRODUCT_CODE
, SUM(A.PRICE * B.SALES_AMOUNT) AS SALES
FROM PRODUCT A, OFFLINE_SALE B
WHERE A.PRODUCT_ID = B.PRODUCT_ID
GROUP BY A.PRODUCT_CODE
ORDER BY SALES DESC, A.PRODUCT_CODE
728x90
320x100