알고리즘/SQL

대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기 ***

베리영young 2024. 9. 3. 02:38

한껏 차이로 계속 틀렸군.....

 

with overfive as (
    select CAR_ID, count(*)
    from CAR_RENTAL_COMPANY_RENTAL_HISTORY
    where month(START_DATE) between 8 and 10 and year(START_DATE)=2022
    group by CAR_ID
    having count(*) >= 5
)
    
-- 코드를 입력하세요
SELECT month(START_DATE) MONTH, CAR_RENTAL_COMPANY_RENTAL_HISTORY.CAR_ID, count(*) RECORDS
from CAR_RENTAL_COMPANY_RENTAL_HISTORY inner join overfive
on CAR_RENTAL_COMPANY_RENTAL_HISTORY.CAR_ID = overfive.CAR_ID
where month(START_DATE) between 8 and 10 and year(START_DATE)=2022
group by MONTH, CAR_ID
order by MONTH, CAR_ID desc