--处理本期同期上期的一个sql
select COALESCE(benqi.area,shangqi.area,tongqi.area) as AllArea,COALESCE(benqi.company,shangqi.company,tongqi.company) as AllCompany,
nvl(benqi.orderNum,0) as benqiOraerNum,nvl(benqi.needNum,0) as benqiNeedNum,nvl(benqi.amount,0) as benQIAmout,
nvl(shangqi.orderNum,0) as shangqiOraerNum,nvl(shangqi.needNum,0) as shangqiNeedNum,nvl(shangqi.amount,0) as shangqiAmout,
nvl(tongqi.orderNum,0) as tongqiOraerNum,nvl(tongqi.needNum,0) as tongqiNeedNum,nvl(tongqi.amount,0) as tongqiAmout
from
(select cig.area as area,cig.company as company,sum(agg.order_num) as orderNum,sum(agg.need_num) as needNum,sum(agg.amount) as amount
from dim_tel_sale_cigarette cig,fact_tel_sale_aggr agg,dim_tel_sale_area area
where (cig.cig_id = agg.cig_id and agg.area_id = area.area_id) and (substr(agg.time_id,0,6) between 200901 and 200907)
group by cig.area,cig.company) benqi FULL OUTER JOIN
(select cig.area as area,cig.company as company,sum(agg.order_num) as orderNum,sum(agg.need_num) as needNum,sum(agg.amount) as amount
from dim_tel_sale_cigarette cig,fact_tel_sale_aggr agg,dim_tel_sale_area area
where (cig.cig_id = agg.cig_id and agg.area_id = area.area_id) and (substr(agg.time_id,0,6) between 200807 and 200812)
group by cig.area,cig.company) shangqi on (benqi.area = shangqi.area and benqi.company = shangqi.company)
FULL OUTER JOIN
(select cig.area as area,cig.company as company,sum(agg.order_num) as orderNum,sum(agg.need_num) as needNum,sum(agg.amount) as amount
from dim_tel_sale_cigarette cig,fact_tel_sale_aggr agg,dim_tel_sale_area area
where (cig.cig_id = agg.cig_id and agg.area_id = area.area_id) and (substr(agg.time_id,0,6) between 200801 and 200807)
group by cig.area,cig.company) tongqi
on (benqi.area = tongqi.area and benqi.company = tongqi.company)
order by AllArea,AllCompany