🙆♀️ 정답 풀이
WITH CTE AS(
SELECT C.CAR_ID,C.CAR_TYPE,C.DAILY_FEE,H.START_DATE,H.END_DATE FROM
CAR_RENTAL_COMPANY_CAR C JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY H
ON C.CAR_ID=H.CAR_ID
WHERE C.CAR_TYPE='세단'or C.CAR_TYPE='SUV')
SELECT DISTINCT C.CAR_ID,P.CAR_TYPE,ROUND((100-discount_rate)/100*DAILY_FEE*30) AS FEE FROM
CAR_RENTAL_COMPANY_DISCOUNT_PLAN P JOIN CTE AS C
ON P.CAR_TYPE=C.CAR_TYPE
WHERE duration_type regexp ('30일 이상')
AND ROUND((100-discount_rate)*0.01*DAILY_FEE*30)>=500000 AND ROUND((100-discount_rate)*0.01*DAILY_FEE*30)<2000000
AND C.CAR_ID NOT IN (SELECT CAR_ID
FROM CTE
WHERE END_DATE>'2022-11-01')
ORDER BY 3 DESC, 2 ASC, 1 DESC;