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

 

프로그래머스

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

programmers.co.kr

 

 

생각 흐름

  • select 절에 바로 start_date와 end_date에서 비교해서 출력하도록 설정
  • car_id의 중복 발견
  • 대여중인 car_id를 고르고 select 절에서 in절로 대여중인지 대여 가능인지 확인

 

 

with rental_car_id as(
    select distinct CAR_ID
    from CAR_RENTAL_COMPANY_RENTAL_HISTORY
    where start_date<='2022-10-16' and '2022-10-16'<=end_date
)

select CAR_ID, (
    case when CAR_ID in (select * from rental_car_id) then '대여중' 
    else '대여 가능' 
    end 
) as AVAILABILITY
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
group by CAR_ID
order by CAR_ID desc

+ Recent posts