코딩테스트/SQL

[JOIN] 5월 식품들의 총매출 조회하기 (☆)

영최 2024. 9. 10. 15:18
728x90

✅ 어떤 테이블 항목인지 명시하는거 잊지말기 O.AMOUNT ...

 총 매출 P.PRICE*SUM(O.AMOUNT)

SELECT P.PRODUCT_ID,P.PRODUCT_NAME,(P.PRICE*SUM(O.AMOUNT)) AS TOTAL_SALES
FROM FOOD_PRODUCT AS P
JOIN FOOD_ORDER AS O ON P.PRODUCT_ID = O.PRODUCT_ID
WHERE O.PRODUCE_DATE >= '2022-05-01' AND PRODUCE_DATE < '2022-06-01'
GROUP BY PRODUCT_ID
ORDER BY TOTAL_SALES DESC, P.PRODUCT_ID
728x90