PRODUCT_ID
SUM(SALES_AMOUNT) * P.PRICE
를 하려고 했는데, GROUP BY를 할 경우에는 그렇게 하면 안돼서, (PRODUCT_ID로 그루핑을 했기 때문에, 그 외의 칼럼은 안됨! 집계함수이면 되지만) 나눠서 해줬다.SELECT P.PRODUCT_CODE, AMOUNT*P.PRICE AS SALES
FROM PRODUCT P, ( SELECT PRODUCT_ID, SUM(SALES_AMOUNT) AS AMOUNT
FROM OFFLINE_SALE
GROUP BY PRODUCT_ID ) O
WHERE P.PRODUCT_ID=O.PRODUCT_ID
ORDER BY SALES DESC, P.PRODUCT_CODE;
SELECT p.product_code, SUM(p.price * o.sales_amount) AS sales
FROM product p, offline_sale o
WHERE p.product_id = o.product_id
GROUP BY p.product_code
ORDER BY sales DESC, product_code;
집계함수 안에 쓰면 되는거였어!
이렇게 또 알아갑니ㄷr..😂
ref.
https://honeynyancat.tistory.com/27