With History2 as (Select *, CASE WHEN Datediff(END_DATE,START_DATE)+1 >= 90 then "90일 이상" WHEN Datediff(END_DATE,START_DATE)+1 >= 30 then "30일 이상" WHEN Datediff(END_DATE,START_DATE)+1 >= 7 then "7일 이상" else NULL end as DURATION_TYPE FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY) SELECT distinct HISTORY_ID as HISTORY_ID, CASE WHEN h.DURATION_TYPE IS NULL THEN FLOOR(DAILY_FEE*(Datediff(END_DATE,START_DAT..