now is better than never
[LEVEL 4][JOIN] 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기 본문
https://school.programmers.co.kr/learn/courses/30/lessons/157339
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
select c.car_id, c.car_type
, round(c.daily_fee * (1 - d.discount_rate/100) * 30) fee
from CAR_RENTAL_COMPANY_CAR c join CAR_RENTAL_COMPANY_DISCOUNT_PLAN d
on c.car_type = d.car_type
join CAR_RENTAL_COMPANY_RENTAL_HISTORY h
on c.car_id = h.car_id
where c.car_type IN ('세단', 'SUV')
and d.duration_type = '30일 이상'
group by c.car_id
having sum(
case when ((start_date < '2022-11-01' and end_date < '2022-11-01')
or (start_date > '2022-11-30' and end_date > '2022-11-30'))
then 0 else 1
end
) = 0
AND fee >= 500000 and fee < 2000000
ORDER BY fee desc, c.car_type, car_id desc
- having절 case when 을 조인할 때 필터링 하는게 나은지 having 절에서 필터링 하는게 나은지,,,?
- 그렇담 다른 조건들은 언제 필터링 하는게 나은지??
'프로그래머스 > SQL' 카테고리의 다른 글
[프로그래머스][Level 3] 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기 (1) | 2023.10.19 |
---|---|
[프로그래머스][Level 4] 자동차 대여 기록 별 대여 금액 구하기 (0) | 2023.10.19 |
[LEVEL 2][String, Date] 자동차 평균 대여 기간 구하기 (0) | 2023.05.15 |
[Level 4][SELECT] 서울에 위치한 식당 목록 출력하기 (0) | 2023.01.04 |
[Level 2][SELECT] 3월에 태어난 여성 회원 목록 출력하기 (SQL 날짜 월 출력) (0) | 2023.01.03 |