https://school.programmers.co.kr/learn/courses/30/lessons/157339
정답
내가 체크못한부분은 ''로 표시함.
-- 코드를 입력하세요
SELECT CAR_ID, CAR_TYPE, FEE
FROM
(
SELECT CAR_ID, CAR_TYPE,
FLOOR(DAILY_FEE * 30 * (SELECT (100-DISCOUNT_RATE)*0.01
FROM CAR_RENTAL_COMPANY_DISCOUNT_PLAN
WHERE DURATION_TYPE = '30일 이상'
AND CAR_TYPE = A.CAR_TYPE )) AS FEE
FROM CAR_RENTAL_COMPANY_CAR A
WHERE CAR_TYPE IN ('세단' ,'SUV')
AND CAR_ID NOT IN (SELECT CAR_ID
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY B
WHERE TO_CHAR(START_DATE, 'YYYY-MM-DD') <= '2022-11-30'
AND TO_CHAR(END_DATE, 'YYYY-MM-DD') >='2022-11-01'
`GROUP BY CAR_ID`)
)
WHERE FEE >= 500000 AND FEE < 2000000
ORDER BY FEE DESC, CAR_TYPE ASC, CAR_ID DESC
SELECT CAR_ID
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY B
WHERE TO_CHAR(START_DATE, 'YYYY-MM-DD') <= '2022-11-30'
AND TO_CHAR(END_DATE, 'YYYY-MM-DD') >='2022-11-01'
`GROUP BY CAR_ID`
CAR_RENTAL_COMPANY_CAR에서 없는 경우만 뽑아라.
또한 CAR_TYPE이 세단이나 SUV여야한다.
DAILY_FEE를 구하는 SELECT문. 30일 이상과 CAR_TYPE이 메인쿼리인 A와 동일한 조건.
SELECT (100-DISCOUNT_RATE)*0.01
FROM CAR_RENTAL_COMPANY_DISCOUNT_PLAN
WHERE DURATION_TYPE = '30일 이상'
AND CAR_TYPE = A.CAR_TYPE )