๐Ÿ’ SQL/Group By

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][SQL] ์›”๋ณ„ ์žก์€ ๋ฌผ๊ณ ๊ธฐ ์ˆ˜ ๊ตฌํ•˜๊ธฐ

์„ ๋‹ฌ 2024. 10. 15. 23:09
๋ฐ˜์‘ํ˜•

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

 

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

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

programmers.co.kr

 

๋ฌธ์ œ

์›”๋ณ„ ์žก์€ ๋ฌผ๊ณ ๊ธฐ์˜ ์ˆ˜์™€ ์›”์„ ์ถœ๋ ฅํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

์žก์€ ๋ฌผ๊ณ ๊ธฐ ์ˆ˜ ์ปฌ๋Ÿผ๋ช…์€ FISH_COUNT, ์›” ์ปฌ๋Ÿผ๋ช…์€ MONTH๋กœ ํ•ด์ฃผ์„ธ์š”.
๊ฒฐ๊ณผ๋Š” ์›”์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”.
๋‹จ, ์›”์€ ์ˆซ์žํ˜•ํƒœ (1~12) ๋กœ ์ถœ๋ ฅํ•˜๋ฉฐ 9 ์ดํ•˜์˜ ์ˆซ์ž๋Š” ๋‘ ์ž๋ฆฌ๋กœ ์ถœ๋ ฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 

์žก์€ ๋ฌผ๊ณ ๊ธฐ๊ฐ€ ์—†๋Š” ์›”์€ ์ถœ๋ ฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

ํ’€์ด

select count(ID) as FISH_COUNT, month(TIME) as MONTH
from FISH_INFO
group by month(TIME)
order by MONTH
๋ฐ˜์‘ํ˜•