日期:2014-05-17 浏览次数:20811 次
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
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