문제
풀이
- 두 테이블 세로로 합치기 : UNION
SELECT (컬럼1), (컬럼2)
FROM (테이블1)
UNION
SELECT (컬럼1), NULL AS (컬럼2) -- 테이블2에 컬럼2가 없는 경우, NULL로 채워서 만들기
FROM (테이블2)
SELECT DATE_FORMAT(SALES_DATE, '%Y-%m-%d') AS SALES_DATE, PRODUCT_ID, USER_ID, SALES_AMOUNT
FROM ONLINE_SALE
WHERE MONTH(SALES_DATE) = 3
UNION
SELECT DATE_FORMAT(SALES_DATE, '%Y-%m-%d') AS SALES_DATE, PRODUCT_ID, NULL AS USER_ID, SALES_AMOUNT
FROM OFFLINE_SALE
WHERE MONTH(SALES_DATE) = 3
ORDER BY SALES_DATE, PRODUCT_ID, USER_ID;
728x90