똑같은 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
'스터디 > Algorithm' 카테고리의 다른 글
[프로그래머스스쿨] 그룹별 조건에 맞는 식당 목록 출력하기 oracle (1) | 2024.09.20 |
---|---|
[프로그래머스스쿨] 입양 시각 구하기(2) oracle (1) | 2024.09.20 |
[프로그래머스스쿨] 상품을 구매한 회원 비율 구하기 oracle (2) | 2024.09.19 |
[백준] 암벽 등반 2412 java -bfs (1) | 2024.09.16 |
[백준] 합이 0 3151 java - 투포인터 (2) | 2024.09.15 |