PROGRAMMERS

[SQL 고득점 Kit][JOIN] 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기

콘순이 2025. 2. 5. 19:36

https://school.programmers.co.kr/learn/courses/30/lessons/157339

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

11월 1일부터 30일까지 예약이 없는 자동차를 조회해야 한다.

SELECT c.car_id, c.car_type, round((c.daily_fee * (100-p.discount_rate) / 100) * 30,0) as fee
from car_rental_company_car c 
left join car_rental_company_rental_history h 
on c.car_id = h.car_id and h.start_date <= '2022-11-30' and h.end_date >= '2022-11-01'
join car_rental_company_discount_plan p on c.car_type = p.car_type
where (c.car_type = 'SUV' or c.car_type = '세단')
and h.car_id is null
and c.daily_fee * 30 between 500000 and 2000000
and p.duration_type = '30일 이상'
order by fee desc, c.car_type, c.car_id desc