내가 작성한 틀린코드
-- 코드를 입력하세요 SELECT EXTRACT(MONTH FROM START_DATE) AS MONTH, CAR_ID, COUNT(CAR_ID) AS RECORDS FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE CAR_ID IN (SELECT CAR_ID FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE (START_DATE) BETWEEN TO_DATE('2022-08-01','YYYY-MM-DD') AND TO_DATE('2022-10-31','YYYY-MM-DD') GROUP BY CAR_ID HAVING COUNT(CAR_ID) >= 5) GROUP BY EXTRACT(MONTH FROM START_DATE), CAR_ID ORDER BY EXTRACT(MONTH FROM START_DATE), CAR_ID DESC
왜 틀렸는지 처음엔 알수없었다.
맞는 코드
-- 코드를 입력하세요 SELECT EXTRACT(MONTH FROM START_DATE) AS MONTH, CAR_ID, COUNT(CAR_ID) AS RECORDS FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE CAR_ID IN (SELECT CAR_ID FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE (START_DATE) BETWEEN TO_DATE('2022-08-01','YYYY-MM-DD') AND TO_DATE('2022-10-31','YYYY-MM-DD') GROUP BY CAR_ID HAVING COUNT(CAR_ID) >= 5) ```AND (START_DATE) BETWEEN TO_DATE('2022-08-01','YYYY-MM-DD') AND TO_DATE('2022-10-31','YYYY-MM-DD')``` GROUP BY EXTRACT(MONTH FROM START_DATE), CAR_ID ```HAVING COUNT(CAR_ID) >= 1``` ORDER BY EXTRACT(MONTH FROM START_DATE), CAR_ID DESC
프로그래머스의 질문란에 나와 반대로 왜 서브쿼리에 써줘야하냐고 질문하신 분이 있었다. 참고하길 바람
https://school.programmers.co.kr/questions/46495