Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sql] 5월 식품들의 총매출 조회하기 #230

Closed
hwangJi-dev opened this issue Apr 28, 2023 · 0 comments
Closed

[Sql] 5월 식품들의 총매출 조회하기 #230

hwangJi-dev opened this issue Apr 28, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

💬 문제

https://school.programmers.co.kr/learn/courses/30/lessons/131117


💬 Idea

  • FOOD_PRODUCT 테이블과 FOOD_ORDER 테이블을 JOIN한다.
    • PK: PRODUCT_ID
  • PRODUCT_ID 를 그룹핑하여 해당 ID별 총 매출액의 합계를 구한다.

💬 풀이

SELECT p.PRODUCT_ID, p.PRODUCT_NAME, SUM((o.AMOUNT * P.PRICE)) AS TOTAL_SALES
FROM FOOD_PRODUCT AS p JOIN FOOD_ORDER AS o
ON p.PRODUCT_ID = o.PRODUCT_ID
WHERE o.PRODUCE_DATE LIKE '2022-05%'
GROUP BY p.PRODUCT_ID
ORDER BY TOTAL_SALES DESC, p.PRODUCT_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant