[프로그래머스 SQL 고득점 Kit] GROUP BY: 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기

jieunee·2023년 3월 31일
0

🤔 문제


✅ 정답

SELECT MONTH(START_DATE) AS MONTH, CAR_ID, COUNT(*) AS RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE START_DATE BETWEEN '2022-08-01' AND '2022-10-31'
    AND 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(CAR_ID) >= 5)
GROUP BY CAR_ID, MONTH(START_DATE)                 
ORDER BY MONTH ASC, CAR_ID DESC
profile
Back-End Developer 🌱

0개의 댓글