SQL
5월 식품들의 총매출 조회하기(프로그래머스 SQL)
wiojfe
2023. 11. 22. 19:25
https://school.programmers.co.kr/learn/courses/30/lessons/131117
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
전체 판매량과 각각 상품의 가격을 곱해서 새로운 데이터를 만들어 주면 된다.
-- 코드를 입력하세요
with order1 as (
SELECT PRODUCT_ID,sum(amount)as amount from food_order where produce_date like '2022-05%' group by PRODUCT_ID)
select o.product_id,f.product_name,(o.amount * f.price ) as total_sales from order1 o inner join food_product f
on o.product_id = f.product_id
order by total_sales desc , o.product_id