#40. JOIN : 상품 별 오프라인 매출 구하기 | 프로그래머스 | SQL 고득점 Kit

문제

 

입력 코드

1. JOIN - ON

SELECT 
    PRODUCT_CODE, 
    SUM(P.PRICE * O.SALES_AMOUNT) AS SALES
FROM PRODUCT AS P
    JOIN OFFLINE_SALE AS O
    ON P.PRODUCT_ID = O.PRODUCT_ID
GROUP BY P.PRODUCT_CODE
ORDER BY SALES DESC, PRODUCT_CODE ASC;

 

2. JOIN - USING

SELECT A.PRODUCT_CODE, SUM(A.PRICE*B.SALES_AMOUNT) AS SALES
FROM PRODUCT A 
    INNER JOIN OFFLINE_SALE B
        USING (PRODUCT_ID)
GROUP BY PRODUCT_CODE, PRICE
ORDER BY SALES DESC, A.PRODUCT_CODE ASC;

 

3. WHERE

SELECT 
    p.product_code product_code, 
    SUM(p.price * o.sales_amount) sales
FROM product p, offline_sale o
    WHERE p.product_id = o.product_id
GROUP BY p.product_id
ORDER BY sales DESC, product_code ASC;

 

코드 설명

#SELECT #JOIN #USING #GROUP BY #ORDER BY #WHERE 

 

문제 출처

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