참조 : https://jmi7313.tistory.com/12
--Mysql
SELECT
YEAR(SALES_DATE) AS YEAR,
MONTH(SALES_DATE) AS MONTH,
GENDER,
COUNT(
DISTINCT ONLINE_SALE.USER_ID
) AS USERS
FROM
ONLINE_SALE
INNER JOIN
USER_INFO
ON
USER_INFO.USER_ID = ONLINE_SALE.USER_ID
WHERE
GENDER IS NOT NULL
GROUP BY
YEAR, MONTH, GENDER
ORDER BY
YEAR, MONTH, GENDER;
--Oracle
SELECT
YEAR,
TO_NUMBER(MONTH) AS MONTH,
GENDER,
COUNT(
DISTINCT
USER_ID
) AS USERS
FROM(
SELECT
TO_CHAR(SALES_DATE,'YYYY') AS YEAR,
TO_CHAR(SALES_DATE,'MM') AS MONTH,
GENDER,
USER_INFO.USER_ID
FROM
USER_INFO,ONLINE_SALE
WHERE
USER_INFO.USER_ID = ONLINE_SALE.USER_ID
AND
GENDER IS NOT NULL
)
GROUP BY
YEAR, MONTH, GENDER
ORDER BY
YEAR ,MONTH,GENDER;
댓글
댓글 쓰기