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

2023. 1. 17. 01:11Programmers/SQL

1
2
3
4
5
6
7
8
SELECT HISTORY_ID, CAR_ID, to_char(start_date, 'yyyy-mm-dd') START_DATE,
        to_char(end_date,'yyyy-mm-dd') END_DATE,
        case when  (end_date - start_date)+1 >= 30 then '장기 대여'
        else  '단기 대여'
        end as RENT_TYPE
from car_rental_company_rental_history
where to_char(start_date, 'yyyy-mm'= '2022-09'
order by history_id desc;
cs

계속 틀렸었던 이유가
(end_date - start_date)+1에서 +1을 생각 못 했음

2023-01-17부터 2023-01-17 하면 1일이니까 +1 해줘야함

날짜를 계산할 때는 항상 주의해야 함!!