DevYoon
[ํ๋ก๊ทธ๋๋จธ์ค] ์ํ ๋ณ ์คํ๋ผ์ธ ๋งค์ถ ๊ตฌํ๊ธฐ (MySQL) ๋ณธ๋ฌธ
PS/Programmers
[ํ๋ก๊ทธ๋๋จธ์ค] ์ํ ๋ณ ์คํ๋ผ์ธ ๋งค์ถ ๊ตฌํ๊ธฐ (MySQL)
gimewn 2022. 10. 29. 00:11link ๐ https://school.programmers.co.kr/learn/courses/30/lessons/131533
๐ญ SQL์ JOIN์ ์จ๋ณด๊ณ ์ถ์ด์ ํ์ด๋ณธ ๋ฌธ์ ! ์ฒ์์ด๋ผ ๊ทธ๋ฐ๊ฐ ๊ฐ์ฅ ์ฌ์ด ๊ฑธ ํ์๋๋ฐ๋ ๋ง์ด ํค๋งธ๋ค๐
๐ญ ๊ทธ๋๋ ์ฌ๋ฐ๋ค!!
๐ญ JOIN์ ON์ผ๋ก ์กฐ๊ฑด ์ฃผ๊ธฐ!! ๊ธฐ์ตํ์!!
SELECT P.PRODUCT_CODE, (P.PRICE * SUM(OFF.SALES_AMOUNT)) AS SALES
FROM PRODUCT AS P JOIN OFFLINE_SALE AS OFF
ON P.PRODUCT_ID = OFF.PRODUCT_ID
GROUP BY P.PRODUCT_ID
ORDER BY SALES DESC, PRODUCT_CODE ASC