-> 최근 3개월 간 판매되어진 정보를 통해 제품별 판매량의 합계
select *
from tbl_panmae_202401 -- 1달 전 데이터
UNION
select *
from tbl_panmae_202312 -- 2달 전 데이터
UNION
select *
from tbl_panmae; -- 이번달 데이터
-- 위치에 상관없이 항상 첫번째 컬럼을 기준으로 오름차순 정렬된다.
-> 최근 3개월 간 판매되어진 정보를 통해 제품별 판매량의 합계
★ 주의 : 컬럼의 순서는 동일해야 한다.
select panmaedate, jepumname, panmaesu
from tbl_panmae_202401 -- 1달 전 데이터
UNION
select panmaedate as 판매일자, jepumname as 제품명
, panmaesu as 판매량
from tbl_panmae_202312 -- 2달 전 데이터
UNION
select panmaedate as "1", jepumname as "2", panmaesu as "3"
from tbl_panmae;
-- 별칭은 항상 처음 select 구문에 있는 것을 사용한다.
-- 다른 별칭은 있어도 사용 X
-> 최근 3개월 간 판매되어진 정보를 통해 제품별 판매량의 합계
★ 주의 : 컬럼의 순서는 동일해야 한다.
WITH
V AS
(
select jepumname, panmaesu
from tbl_panmae_202312 -- 2달 전 데이터
UNION ALL
select jepumname, panmaesu
from tbl_panmae_202401 -- 1달 전 데이터
UNION ALL
select jepumname, panmaesu
from tbl_panmae -- 이번달 데이터
)
SELECT V.jepumname as 제품명, sum(panmaesu) as 판매량
FROM V
GROUP BY V.jepumname
ORDER BY 1;
-> local_hr에서작업한것