select yf 月份 ,a.cpdh 产品代号 ,b.cpxh 产品型号 ,a.snum 计划数量 ,c.snum 销售数量 from (select yf,cpdh,sum(s1) snum form jhb group by yf,cpdh) a,对照表 b,(select yf,cpdh,sum(s1) snum from xsb group by yf,cpdh) c where a.cpdh=b.cpdh and c.cpdh=b.cpdh and a.yf=c.yf
select A.yf,A.cpdh,B.sl,C.sl from (select yf,cpdh from jhb union select yf,cpdh from xsb) A,jhb B,xsb C where A.yf=B.yf(+) and A.cpdh=B.cpdh(+) and a.yf=c.yf(+) and a.cpdh=c.cpdh(+)
我这不需要求出sum(),只要取出现存的数据就可以。
按照你的方法,只能查询出两张表都有相同产品代号的列
(select yf,cpdh from jhb
union
select yf,cpdh from xsb) A,jhb B,xsb C where A.yf=B.yf(+) and A.cpdh=B.cpdh(+) and a.yf=c.yf(+) and a.cpdh=c.cpdh(+)
奥,还要和产品型号对照表 关连一次,取出cpxh.