๋ฌธ์
์๋์ฐจ ๋์ฌ ๊ธฐ๋ก ๋ณ ๋์ฌ ๊ธ์ก ๊ตฌํ๊ธฐ
ํ์ด
SELECT AA.HISTORY_ID, (AA.RENT_DATE * AA.DAILY_FEE) * (100 - NVL(DISCOUNT_RATE, 0)) / 100 FEE
FROM
(SELECT
HISTORY_ID,
H.END_DATE - H.START_DATE + 1 RENT_DATE,
CASE
WHEN H.END_DATE - H.START_DATE + 1 >= 90 THEN '90์ผ ์ด์'
WHEN H.END_DATE - H.START_DATE + 1 >= 30 THEN '30์ผ ์ด์'
WHEN H.END_DATE - H.START_DATE + 1 >= 7 THEN '7์ผ ์ด์'
END AS DURATION_TYPE,
CAR_TYPE,
DAILY_FEE
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY H LEFT JOIN CAR_RENTAL_COMPANY_CAR C
ON H.CAR_ID = C.CAR_ID) AA LEFT JOIN CAR_RENTAL_COMPANY_DISCOUNT_PLAN D
ON AA.DURATION_TYPE = D.DURATION_TYPE AND AA.CAR_TYPE = D.CAR_TYPE
WHERE AA.CAR_TYPE = 'ํธ๋ญ'
ORDER BY FEE DESC, HISTORY_ID DESC
;
- CAR_RENTAL_COMPANY_RENTAL_HISTORY์ CAR_RENTAL_COMPANY_CAR๋ฅผ ์กฐ์ธํ๊ณ DURATION_TYPE์ด ์ถ๊ฐ๋ ์ธ๋ผ์ธ๋ทฐ๋ฅผ ๋ง๋ค๊ณ , CAR_RENTAL_COMPANY_DISCOUNT_PLAN๊ณผ ์กฐ์ธํ์ฌ ํ์ดํ์ต๋๋ค.