now is better than never

[프로그래머스][Level 3] 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기 본문

프로그래머스/SQL

[프로그래머스][Level 3] 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기

김초송 2023. 10. 19. 22:28
SELECT date_format(start_date, '%m') month
    , car_id
    , count(*) RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE car_id in (select car_id
                  from CAR_RENTAL_COMPANY_RENTAL_HISTORY
                  where START_DATE between '2022-08-01' and '2022-10-31'
                  group by car_id
                  having count(*)>=5)
    AND START_DATE between '2022-08-01' and '2022-10-31'
GROUP BY month, car_id
HAVING records > 0
ORDER BY month asc, car_id desc

더 깔끔하게 푸는 방법은 없을까,,,?