코딩테스트/SQL
[SQL] 프로그래머스 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기(*)
유(YOO)
2023. 2. 10. 23:09
https://school.programmers.co.kr/learn/courses/30/lessons/157339
SELECT
CAR_ID,
A.CAR_TYPE,
ROUND(DAILY_FEE / 100 * 30 * (100 - DISCOUNT_RATE)) AS FEE
FROM CAR_RENTAL_COMPANY_CAR A
JOIN CAR_RENTAL_COMPANY_DISCOUNT_PLAN B
ON A.CAR_TYPE = B.CAR_TYPE AND DURATION_TYPE = "30일 이상"
WHERE CAR_ID NOT IN (
SELECT CAR_ID
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE NOT (START_DATE > "2022-11-30" OR END_DATE < "2022-11-01"))
AND (A.CAR_TYPE = "세단" OR A.CAR_TYPE = "SUV")
AND ROUND(DAILY_FEE / 100 * 30 * (100 - DISCOUNT_RATE)) BETWEEN 500000 AND 2000000
ORDER BY FEE DESC, CAR_TYPE, CAR_ID DESC;