๐Ÿ’ SQL/String, Date

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][MySQL] ๋ถ„๊ธฐ๋ณ„ ๋ถ„ํ™”๋œ ๋Œ€์žฅ๊ท ์˜ ๊ฐœ์ฒด ์ˆ˜ ๊ตฌํ•˜๊ธฐ (level2)

์„ ๋‹ฌ 2024. 11. 6. 17:07
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

๊ฐ ๋ถ„๊ธฐ(QUARTER)๋ณ„ ๋ถ„ํ™”๋œ ๋Œ€์žฅ๊ท ์˜ ๊ฐœ์ฒด์˜ ์ด ์ˆ˜(ECOLI_COUNT)๋ฅผ ์ถœ๋ ฅํ•˜๋Š” SQL ๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋•Œ ๊ฐ ๋ถ„๊ธฐ์—๋Š” 'Q' ๋ฅผ ๋ถ™์ด๊ณ  ๋ถ„๊ธฐ์— ๋Œ€ํ•ด ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”. ๋Œ€์žฅ๊ท  ๊ฐœ์ฒด๊ฐ€ ๋ถ„ํ™”๋˜์ง€ ์•Š์€ ๋ถ„๊ธฐ๋Š” ์—†์Šต๋‹ˆ๋‹ค.

 

ํ’€์ด

select
    case 
        when month(DIFFERENTIATION_DATE) between 1 and 3 then '1Q'
        when month(DIFFERENTIATION_DATE) between 4 and 6 then '2Q'
        when month(DIFFERENTIATION_DATE) between 7 and 9 then '3Q'
        when month(DIFFERENTIATION_DATE) between 10 and 12 then '4Q'
    end as QUARTER,
    count(ID) as ECOLI_COUNT
from ECOLI_DATA
group by QUARTER
order by QUARTER asc
๋ฐ˜์‘ํ˜•