참고 링크 : 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
'SQL > Programmers' 카테고리의 다른 글
Programmers - 그룹별 조건에 맞는 식당 목록 출력하기 (56%) (0) | 2023.02.19 |
---|---|
Programmers - 상품을 구매한 회원 비율 구하기(38%) (0) | 2023.02.19 |
Programmers - 대여 기록이 존재하는 자동차 리스트 구하기(71%) (0) | 2023.02.19 |
Programmers - 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기(55%) (0) | 2023.02.18 |
Promrammers - 자동차 대여 기록 별 대여 금액 구하기(29%) (0) | 2023.02.18 |