๐Ÿ’ซ ๋ฌธ์ œ



ย 

๐Ÿ’ซ CODE

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

ย 

๐Ÿ’ซ ํ’€์ด ์กฐ๊ฑด

1. ์ƒํ’ˆ์ฝ”๋“œ ๋ณ„ ๋งค์ถœ์•ก(ํŒ๋งค๊ฐ€ * ํŒ๋งค๋Ÿ‰) ํ•ฉ๊ณ„๋ฅผ ์ถœ๋ ฅ
2. ๋งค์ถœ์•ก์„ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ, ๋งค์ถœ์•ก์ด ๊ฐ™๋‹ค๋ฉด ์ƒํ’ˆ์ฝ”๋“œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ

ย 

๐Ÿ’ซ ํ’€์ด

1. SELECT a.PRODUCT_CODE, SUM(a.PRICE * b.SALES_AMOUNT) AS SALES
  • PRODUCT ํ…Œ์ด๋ธ”์˜ ์ƒํ’ˆ์ฝ”๋“œ(PRODUCT_CODE), SUM(PRODUCT ํ…Œ์ด๋ธ”์˜ ํŒ๋งค๊ฐ€(PRICE) * PRODUCT ํ…Œ์ด๋ธ”์˜ ํŒ๋งค๋Ÿ‰(SALES_AMOUNT))
  • SUM()์„ ์ด์šฉํ•˜์—ฌ PRODUCT ํ…Œ์ด๋ธ”์˜ ํŒ๋งค๊ฐ€(PRICE) * PRODUCT ํ…Œ์ด๋ธ”์˜ ํŒ๋งค๋Ÿ‰(SALES_AMOUNT)์˜ ํ•ฉ๊ณ„ ๊ตฌํ•˜๊ธฐ
  • AS๋ฅผ ์ด์šฉํ•˜์—ฌ SUM(a.PRICE * b.SALES_AMOUNT) ๋ณ„์นญ SALES ์ง€์ •
2. FROM PRODUCT a
  • PRODUCT ํ…Œ์ด๋ธ” ๋ณ„์นญ a๋กœ ์ง€์ •
3. JOIN OFFLINE_SALE b ON a.PRODUCT_ID = b.PRODUCT_ID
  • OFFLINE_SALE ํ…Œ์ด๋ธ” ๋ณ„์นญ b๋กœ ์ง€์ •
  • a.PRODUCT_ID = b.PRODUCT_ID ๊ณต์œ ํ•˜๊ณ ์žˆ๋Š” ์ปฌ๋Ÿผ
4. GROUP BY PRODUCT_CODE
  • ์ƒํ’ˆ์ฝ”๋“œ(PRODUCT_CODE)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ง‘๊ณ„
5. ORDER BY SALES DESC, PRODUCT_CODE ASC
  • ๋งค์ถœ์•ก(SALES)์„ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ, ์ƒํ’ˆ์ฝ”๋“œ(PRODUCT_CODE)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ

By Dozzing

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค