各位都来看看
1.inv01 (入库记录表)
inv01code 入库单号
itemcode 物料代码
itemdesc 物料名称
quantity 入库数量
inv01date 入库日期
2.inv02 (出库记录表)
inv02code 出库单号
itemcode 物料代码
itemdesc 物料名称
quantity 出库数量
inv02date 出库日期
3.mrptmp (物料表)
itemcode 物料代码
itemdesc 物料名称
能否写一条语句﹐求一段时间内的入库总数﹐出库总数(没有出(入)库的为0)
如﹕
物料编码 物料名称 入库总数 出库总数
001 aafea 25 50
002 fafae 60 0
003 dfsf 0 0
问题点数:60、回复次数:2Top
1 楼Softlee81307(孔腎)回复于 2005-01-27 08:27:30 得分 20
select itemCode,itemdesc,
入库总数=isnull((select sum(quantity) from inv01 where itemcode=mrptmp.itemcode and inv01date>=謀起點日期 and inv01date<=止日期),0) ,
出库总数=isnull((select sum(quantity) from inv02 where itemcode=mrptmp.itemcode and inv02date>=謀起點日期 and inv02date<=止日期),0)
from mrptmpTop
2 楼zjcxc(邹建)回复于 2005-01-27 08:29:02 得分 40
select 物料编码=a.itemcode,物料名称=a.itemdesc
,入库总数=isnull(sum(b.quantity_in),0)
,出库总数=isnull(sum(b.quantity_out),0)
from mrptmp a
left join(
select itemcode,quantity_in=quantity,quantity_out=0
from inv01
where 入库日期 between '2005-1-1' and '2005-1-31'
union all
select itemcode,quantity_in=0,quantity_out=quantity
from inv02
where 出库日期 between '2005-1-1' and '2005-1-31'
)b on a.itemcode=b.itemcode
group by a.itemcode,a.itemdesc
Top




