스터디/Algorithm

[프로그래머스스쿨] 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기 oracle

혜유우 2024. 9. 20. 14:18

똑같은 car_id를 가진 차에 대한 대여 기록이 여러 개 있을 수 있다

따라서 11월에 대여 가능한 차를 조회하기 위해서는

11월에 대여 불가능한 차(car_id)를 먼저 서브쿼리로 선별한 후에

이에 해당하지 않는 차를 not in으로 골라내야 한다!!

 

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

 

select c.car_id, c.car_type, 30*c.daily_fee*(1-p.discount_rate*0.01) as fee
from car_rental_company_car c inner join car_rental_company_discount_plan p 
                                         on c.car_type=p.car_type
where c.car_type in ('세단', 'SUV')
and p.duration_type='30일 이상'
and 30*c.daily_fee*(1-p.discount_rate*0.01) between 500000 and 2000000
and c.car_id not in (select car_id
                     from car_rental_company_rental_history
                     where to_char(end_date,'YYYYMM')>='202211' 
                     and to_char(start_date,'YYYYMM')<='202211'                 
                    )
order by 3 desc, 2, 1 desc