如何使用SQL语句实现这个功能?

xiaoxu2002 2003-10-17 10:14:06
从产品的入库表(indepot)中减去产品出库表(outdepot)加上产品库存表(depot)的每种产品数据,得出当前产品的库存信息?如何用SQL语句实现?
...全文
103 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhongminsheng 2003-10-17
  • 打赏
  • 举报
回复
从产品的入库表(indepot)中减去产品出库表(outdepot)加上产品库存表(depot)的每种产品数据,得出当前产品的库存信息?如何用SQL语句实现?

select depot.*, rk.rsl as 入库数量,ck.csl as 出库数量,depot.kc+rk.sl-rck.csl as 当前库存 from depot left outer join (select indepot.bh, sum(indepot.sl) as rsl from indepot group by indepot.bh) as rk on rk.bh=depot.bh left outer join (select outdepot.bh, sum(outdepot.sl) as csl from outdepot group by outdepot.bh) as ck on ck.bh=depot.bh
zjcxc 2003-10-17
  • 打赏
  • 举报
回复
ACCESS数据库不支持全连接.因此你需要一个商品表.
zjcxc 2003-10-17
  • 打赏
  • 举报
回复
--SQL数据库
select isnull(a.名称,b.名称,c.名称),a.入库-b.出库+c.库存
from indepot a full join outdepot b on a.名称=b.名称
full join depot c on a.名称=c.名称
golden24kcn 2003-10-17
  • 打赏
  • 举报
回复
select a.名称,a.库存 + (select sum(b.入库数量) from indepot b where b.id=a.id) - (select C.出库数量 from outdepot c where c.id=a.id) from depot a

试试!!!
strongfisher 2003-10-17
  • 打赏
  • 举报
回复
select sum(indepot.a)-sum(outdepot.a)+sum(depot.a) as 总计 from depot,depot,indepot where indepot.id=outdepot.id and outdepot.id=depot.id

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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