๐Ÿ’ SQL/Group By

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] SQL ๊ณ ๋“์  Kit: ์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„ ๋„์„œ ํŒ๋งค๋Ÿ‰ ์ง‘๊ณ„ํ•˜๊ธฐ

์„ ๋‹ฌ 2023. 5. 16. 23:31
๋ฐ˜์‘ํ˜•

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

 

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

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

programmers.co.kr

 

-- ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”
select CATEGORY, sum(SALES) as TOTAL_SALES
from BOOK b join BOOK_SALES s on b.BOOK_ID = s.BOOK_ID
where year(SALES_DATE) = 2022 and month(SALES_DATE) = 01
group by CATEGORY
order by CATEGORY
๋ฐ˜์‘ํ˜•