select a.xf_storecode,a.xf_tillid,a.xf_docno,a.xf_plu,q.活动扣率,(cast(a.xf_qtysold as float)) as 退货数量 ,(cast(a.xf_amtsold as float)) as 退货金额,TO_CHAR(a.xf_createtime, 'YYYY-MM-DD') as 货品销售日期,
a.xf_suppcode,a.xf_bscontractstorecode,a.xf_bscontractno,b.xf_desci,q.xf_bspromcontractno,q.xf_cutoffdate,q.xf_effectdate
from xf_transsalesitem a left join xf_itemmas b on a.xf_plu=b.xf_plu
left join (select c.xf_bspromcontractno,c.xf_storecode,c.xf_bscontractno,c.xf_plu,c.xf_bsvalue as 活动扣率,c.xf_lastmodtime,
d.xf_effectdate,d.xf_cutoffdate from xf_bspromcontractd c left join xf_bspromcontracth d on c.xf_bspromcontractno=d.xf_bspromcontractno) q
on a.xf_bscontractno=q.xf_bscontractno and q.xf_plu= a.xf_plu
where xf_amtsold < 0
and TO_CHAR(a.xf_createtime, 'YYYY-MM-DD') between to_char(q.xf_effectdate,'yyyy-mm-dd') and to_char(q.xf_cutoffdate,'yyyy-mm-dd')
order by a.xf_txdate desc
--------关于活动期的商品退货
--------筛出退货商品
--------找出促销合同明细
--------通过合同和商品号连接退货商品表,并且把货品销售日期在活动区间的商品活动扣率补充上
--------本想把非活动商品也放到一起,没有想到好的办法,因为
1、是用退货表中的商品合同号关联的促销合同中的合同号,因为含有多个促销合同,造成了一对多的情况
2、填充商品扣率时,由于1的情况无法正常填充
3、后来添加 促销合同内商品号与退货表商品号连接直接剔除了非活动商品、、、、、、、