💻 SQL 고득점 Kit > JOIN > 문제
✏️ 풀이
👉 제출 코드
SELECT DISTINCT(C.CAR_ID), C.CAR_TYPE, ROUND(DAILY_FEE * (1 - DISCOUNT_RATE / 100) * 30) AS FEE
FROM CAR_RENTAL_COMPANY_CAR C
JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY H
ON C.CAR_ID = H.CAR_ID
JOIN CAR_RENTAL_COMPANY_DISCOUNT_PLAN P
ON C.CAR_TYPE = P.CAR_TYPE
WHERE C.CAR_TYPE IN ('세단', 'SUV')
AND C.CAR_ID NOT IN (SELECT CAR_ID
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE START_DATE BETWEEN '2022-11-01' AND '2022-11-30 59:59:59'
OR END_DATE BETWEEN '2022-11-01' AND '2022-11-30 59:59:59'
OR START_DATE <= '2022-11-01' AND END_DATE >= '2022-11-30')
AND P.DURATION_TYPE = '30일 이상'
AND ROUND(DAILY_FEE * (1 - DISCOUNT_RATE / 100) * 30) BETWEEN 500000 AND 2000001
ORDER BY 3 DESC, 2, 1 DESC