https://school.programmers.co.kr/learn/courses/30/lessons/157339
적절 히 조건을 분기한 뒤, subquery를 통해 구했다.
select ccdd.car_id , ccdd.car_type,
truncate ( (ccdd.daily_fee*(100-ccdd.discount_rate)/100)*30,0 ) as fee
from
(select car_id,daily_fee, discount_rate,crcc.car_type # 할인 후에 50~200만 사이인 차
from CAR_RENTAL_COMPANY_CAR as crcc join CAR_RENTAL_COMPANY_DISCOUNT_PLAN as crcd
where crcc.car_type = crcd.car_type
and duration_type ="30일 이상"
and (crcc.car_type ="세단" or crcc.car_type="SUV") ) as ccdd
where
car_id not in #2022-11-01~2022-11-30 동안 대여 가능한 차.
(SELECT car_id
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
where substring(start_date,1,10) < '2022-11-31' and substring(end_date,1,10) > '2022-11-00')
# HAVING 에서 SELECT의 ALIAS(fee) 가 적용되는건 MYSQL에서만 허용되는 예외적 문법이다.
having 499999<fee and fee <2000000
order by fee desc, ccdd.car_type asc, ccdd.car_id desc
'코딩테스트' 카테고리의 다른 글
대여 기록이 존재하는 자동차 리스트 구하기 (1) | 2023.07.20 |
---|---|
sql 사용 완전 공략 [mysql] (0) | 2023.07.20 |
카카오 블라인드 채용 2023 미로 탈출 명령어 c++ [사전 순] (0) | 2023.07.18 |
[카카오 블라인드 채용 2023] 표현 가능한 이진트리 (0) | 2023.07.17 |
2023 카카오 블라인드 채용 이모티콘 행사 c++ (브루트 포스) (0) | 2023.07.17 |