Study

[프로그래머스/Mysql] 오프라인/온라인 판매 데이터 통합하기

코딩콩 2024. 12. 9. 23:02

https://school.programmers.co.kr/learn/courses/30/lessons/131537

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

정답

select date_format(sales_date, '%Y-%m-%d'), product_id, user_id, sales_amount
from (SELECT sales_date, product_id, null as user_id, sales_amount
from offline_sale ofs
union all
select sales_date, product_id, user_id, sales_amount
from online_sale os) as a
where date_format(sales_date, '%Y-%m') = '2022-03'
order by sales_date asc, product_id asc, user_id asc

 

union은 중복 제거, union all은 중복 제거 X