DevYoon

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ƒํ’ˆ ๋ณ„ ์˜คํ”„๋ผ์ธ ๋งค์ถœ ๊ตฌํ•˜๊ธฐ (MySQL) ๋ณธ๋ฌธ

PS/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ƒํ’ˆ ๋ณ„ ์˜คํ”„๋ผ์ธ ๋งค์ถœ ๊ตฌํ•˜๊ธฐ (MySQL)

gimewn 2022. 10. 29. 00:11

link ๐Ÿ”— https://school.programmers.co.kr/learn/courses/30/lessons/131533

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

๐Ÿ’ญ 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