Development/Algorithm & Coding Test
[프로그래머스] 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기 - MySQL
컴공 K
2023. 4. 25. 02:00
[프로그래머스] 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기 - MySQL
SELECT MONTH(START_DATE) AS MONTH, CAR_ID, COUNT(HISTORY_ID) AS RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE CAR_ID IN (
SELECT CAR_ID FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE DATE_FORMAT(START_DATE,'%Y-%m') BETWEEN '2022-08' AND '2022-10'
GROUP BY CAR_ID HAVING COUNT(CAR_ID) >= 5
)
AND DATE_FORMAT(START_DATE,'%Y-%m') BETWEEN '2022-08' AND '2022-10'
GROUP BY MONTH, CAR_ID
ORDER BY MONTH ASC, CAR_ID DESC;
https://school.programmers.co.kr/learn/courses/30/lessons/151139
728x90