๐Ÿ’ SQL (Programmers)/String, Date

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][SQL] ์—ฐ๋„ ๋ณ„ ํ‰๊ท  ๋ฏธ์„ธ๋จผ์ง€ ๋†๋„ ์กฐํšŒํ•˜๊ธฐ

์„ ๋‹ฌ 2024. 9. 25. 12:38
๋ฐ˜์‘ํ˜•

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

 

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

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

programmers.co.kr

 

๋ฌธ์ œ

AIR_POLLUTION ํ…Œ์ด๋ธ”์—์„œ 

์ˆ˜์› ์ง€์—ญ์˜ ์—ฐ๋„ ๋ณ„ ํ‰๊ท  ๋ฏธ์„ธ๋จผ์ง€ ์˜ค์—ผ๋„์™€ ํ‰๊ท  ์ดˆ๋ฏธ์„ธ๋จผ์ง€ ์˜ค์—ผ๋„๋ฅผ ์กฐํšŒํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. 

์ด๋•Œ, ํ‰๊ท  ๋ฏธ์„ธ๋จผ์ง€ ์˜ค์—ผ๋„์™€ ํ‰๊ท  ์ดˆ๋ฏธ์„ธ๋จผ์ง€ ์˜ค์—ผ๋„์˜ ์ปฌ๋Ÿผ๋ช…์€ ๊ฐ๊ฐ PM10, PM2.5๋กœ ํ•ด ์ฃผ์‹œ๊ณ , 

๊ฐ’์€ ์†Œ์ˆ˜ ์…‹์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผํ•ด์ฃผ์„ธ์š”.
๊ฒฐ๊ณผ๋Š” ์—ฐ๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”.

 

ํ’€์ด

select year(YM) as YEAR, 
    round(avg(PM_VAL1), 2) as PM10, 
    round(avg(PM_VAL2), 2) as 'PM2.5'
from AIR_POLLUTION
where LOCATION2 = '์ˆ˜์›'
group by year(YM)
order by YEAR asc
๋ฐ˜์‘ํ˜•