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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][SQL] ์กฐ๊ฑด๋ณ„๋กœ ๋ถ„๋ฅ˜ํ•˜์—ฌ ์ฃผ๋ฌธ์ƒํƒœ ์ถœ๋ ฅํ•˜๊ธฐ

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

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

 

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

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

programmers.co.kr

 

-- ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”
SELECT ORDER_ID, PRODUCT_ID, date_format(OUT_DATE, "%Y-%m-%d") as OUT_DATE,
    case when OUT_DATE is null then '์ถœ๊ณ ๋ฏธ์ •'
    when OUT_DATE <= '2022-05-01' then '์ถœ๊ณ ์™„๋ฃŒ'
    when OUT_DATE > '2022-05-01' then '์ถœ๊ณ ๋Œ€๊ธฐ'
    end as ์ถœ๊ณ ์—ฌ๋ถ€
from FOOD_ORDER
order by ORDER_ID
๋ฐ˜์‘ํ˜•