处理本期同期上期的一个sql

--处理本期同期上期的一个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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值