Coding Test
[SQL 프로그래머스] 상품 별 오프라인 매출 구하기
hyungminjeon
2024. 6. 21. 15:00
[문제]
[해결]
SELECT product_code, sum(SALES_AMOUNT*PRICE) as SALES
from PRODUCT
inner join OFFLINE_SALE
USING(product_id)
group by product_code
order by SALES DESC, PRODUCT_CODE ASC;
[정리 및 새롭게 알게 된 점]
1. 먼저 product 테이블과 offline_sale 테이블을 product_id 기준으로 조인한 다음
2. group by 절로 product_code 기준으로 그룹을 묶어주고,
3. product_code와 sum(sales_amount*price)를 select 하였다.
4. 마지막으로 sales를 기준으로 내림차순, product_code를 기준으로 오름차순 정렬하였다.