-- 코드를 입력하세요
SELECT MONTH(START_DATE) AS MONTH,
CAR_ID, COUNT(HISTORY_ID) AS RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE START_DATE BETWEEN '2022-08-01' AND '2022-10-31'
GROUP BY MONTH, CAR_ID
HAVING COUNT(HISTORY_ID) >= 5
ORDER BY MONTH ASC, CAR_ID DESC;
-- 코드를 입력하세요
SELECT MONTH(START_DATE) AS MONTH, CAR_ID,
COUNT(HISTORY_ID) AS RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE CAR_ID IN(
SELECT C.CAR_ID
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY AS C
WHERE C.START_DATE BETWEEN '2022-08-01' AND '2022-10-31'
GROUP BY C.CAR_ID
HAVING COUNT(C.CAR_ID) >= 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
쿼리를 하나 더넣어서 하는 서브쿼리가 아직 미숙하다
좀더 고민하면서 해봐야겠다.