用UNION是可以实现,能不能有比较方便的方法呢?

解决方案 »

  1.   

    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
      

  2.   

    beckhambobo(beckham) 兄,您可能理解错了
    我这不需要求出sum(),只要取出现存的数据就可以。
    按照你的方法,只能查询出两张表都有相同产品代号的列
      

  3.   

    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(+)
      

  4.   

    上面的SQL没试,如果不行的话,可以把上面的A和jhb、xsb分别做外连接,然后对他们的结果再连接一次,应该可以得到你要的结果。
    奥,还要和产品型号对照表 关连一次,取出cpxh.