各位都来看看

NICOJOHN 2005-01-27 08:15:05
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
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2005-01-27
  • 打赏
  • 举报
回复
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
Softlee81307 2005-01-27
  • 打赏
  • 举报
回复
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 mrptmp

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧