SQL/Programmers
Programmers - 자동차 대여 기록에서 대여중 / 대여 가능 여부 구분하기(67%)
소HS군
2023. 2. 19. 00:14
참고 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/157340
C>
Q>
H>
- left 함수 사용
- 날짜 between start_date and end_date
L&U>
- 날짜를 between 에 넣어서 활용할 수 있는 접근이 기억에 남았다
- 테이블 조인을 활용해 null 값을 도출하는 과정이 인상 깊었다.
U: 이벤트 날짜가 구매 날짜에 걸리냐 안걸리냐에 따라서 userid 추출이 가능할 것 같다.
A>
with t1 as (
SELECT distinct car_id as car_id
from car_rental_company_rental_history
order by 1 desc
)
, t2 as (
select car_id
from car_rental_company_rental_history
where '2022-10-16' between start_date and end_date
)
select t1.car_id AS CAR_ID
, case when t2.car_id is null then '대여 가능' else '대여중' end as AVAILABILITY
from t1
left join t2
on t1.car_id = t2.car_id