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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] SQL ๊ณ ๋“์  Kit : ์ž๋™์ฐจ ๋Œ€์—ฌ ๊ธฐ๋ก์—์„œ ์žฅ๊ธฐ/๋‹จ๊ธฐ ๋Œ€์—ฌ ๊ตฌ๋ถ„ํ•˜๊ธฐ

์„ ๋‹ฌ 2023. 4. 4. 23:38
๋ฐ˜์‘ํ˜•

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

 

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

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

programmers.co.kr

 

-- ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”
SELECT HISTORY_ID, CAR_ID, 
date_format(START_DATE, '%Y-%m-%d') as START_DATE, 
date_format(END_DATE, '%Y-%m-%d') as END_DATE,
if(datediff(END_DATE, START_DATE)+1>=30, "์žฅ๊ธฐ ๋Œ€์—ฌ", "๋‹จ๊ธฐ ๋Œ€์—ฌ") as RENT_TYPE
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
where START_DATE like "2022-09%"
order by HISTORY_ID desc
๋ฐ˜์‘ํ˜•