틀린답
SELECT YEAR(OS.SALES_DATE) YEAR, MONTH(OS.SALES_DATE) MONTH, UI.GENDER, COUNT(OS.USER_ID) USERS
FROM USER_INFO UI
JOIN ONLINE_SALE OS
ON UI.USER_ID = OS.USER_ID
WHERE UI.GENDER IS NOT NULL
GROUP BY YEAR, MONTH, GENDER
ORDER BY YEAR, MONTH, GENDER
정답
SELECT YEAR(OS.SALES_DATE) YEAR, MONTH(OS.SALES_DATE) MONTH, UI.GENDER, COUNT(DISTINCT(UI.USER_ID)) USERS
FROM USER_INFO UI
JOIN ONLINE_SALE OS
ON UI.USER_ID = OS.USER_ID
WHERE UI.GENDER IS NOT NULL
GROUP BY YEAR, MONTH, GENDER
ORDER BY YEAR, MONTH, GENDER
테이블 보고도 왜 틀렸는지를 모르겠어서 진짜 혹시나해서 넣어본건데 distinct
때문이라니.. 한달에 여러번 산 사람을 제외해야한다는 걸.. 전혀 생각을 못했다니 와......................