有4个表采购主表
tcghead
billno,rcdate
采购明细
billno,barcode,cgcount收货主表
shhead
billno,rcdate
收货明细
billno,barcode,shcount要求某一时间段内某一条码的(采购汇总-收货汇总)。

解决方案 »

  1.   

    可否上点模拟数据,看你的需求应该是根据一个条形码  来查询出2个汇总信息  每个汇总信息来源于2个表
    感觉采购主表billno和采购明细billno关联即可查询出采购汇总,
    收货应该同上! 
      

  2.   

    这样 ?
    select billno,ccount,scount
    from (
    select a.billno,sum(b.cgcount) ccount
    from 采购主表 a,采购明细 b  
    where a.billno = b.billno 
          and a.rcdate between 开始时间 and 结束时间 ) t1,
    (
    select c.billno,sum(d.shcount) scount
    from 收货主表 c,收货明细 d  
    where c.billno = d.billno 
          and c.rcdate between 开始时间 and 结束时间
    ) t2
    where t1.billno = t2.billno
      

  3.   

    看起来很简单嘛
    几个表一关联,sum一下就出来了
      

  4.   

    select ( sum(a.cgcount)-sum(b.shcount) ) ,a.billon from 采购明细 a,收货明细 b 
     where a.billno in (select billno from tcghead  where rcdate between  stime and etime ) group by a.billon