ji-0630 / CodingTest

코딩테스트 연습 기록
0 stars 0 forks source link

자동차 대여 기록에서 장기/단기 대여 구분하기 #249

Closed ji-0630 closed 1 year ago

ji-0630 commented 1 year ago

문제 설명

image

ji-0630 commented 1 year ago

나의 풀이

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", case when (END_DATE - START_DATE) +1 >= 30 then "장기 대여"
         else "단기 대여" end as "RENT_TYPE"
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
where date_format(START_DATE, "%Y-%m") = "2022-09"
order by HISTORY_ID desc
ji-0630 commented 1 year ago

다른 사람의 풀이

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", case when datediff(END_DATE, START_DATE) >= 29 then "장기 대여"
         else "단기 대여" end as "RENT_TYPE"
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
where date_format(START_DATE, "%Y-%m") = "2022-09"
order by HISTORY_ID desc
ji-0630 commented 1 year ago

다시 풀기

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", case when datediff(END_DATE, START_DATE) >= 29 then "장기 대여"
                                else "단기 대여" end as "RENT_TYPE"
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
where date_format(START_DATE, "%Y-%m") = "2022-09"
order by HISTORY_ID desc