ji-0630 / CodingTest

코딩테스트 연습 기록
0 stars 0 forks source link

오프라인/온라인 판매 데이터 통합하기 #167

Closed ji-0630 closed 1 year ago

ji-0630 commented 1 year ago

문제 설명

image image image

ji-0630 commented 1 year ago

나의 풀이

select date_format(SALES_DATE, "%Y-%m-%d") as SALES_DATE, PRODUCT_ID, USER_ID, SALES_AMOUNT
from ONLINE_SALE
where year(SALES_DATE) = 2022
and 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 year(SALES_DATE) = 2022
and month(SALES_DATE) = 3

order by sales_date, product_id, user_id
ji-0630 commented 1 year ago

다시 풀기

SELECT date_format(SALES_DATE, "%Y-%m-%d") as "SALES_DATE", PRODUCT_ID, NULL as "USER_ID", SALES_AMOUNT
from OFFLINE_SALE
where date_format(SALES_DATE, "%Y-%m") = "2022-03"
union
select date_format(SALES_DATE, "%Y-%m-%d") as "SALES_DATE", PRODUCT_ID, USER_ID, SALES_AMOUNT
from ONLINE_SALE
where date_format(SALES_DATE, "%Y-%m") = "2022-03"
order by SALES_DATE, PRODUCT_ID, USER_ID