使用2个表时,如何在SQL中更新表中的库存 [英] How do I update the stock in a table in SQL when using 2 tables
本文介绍了使用2个表时,如何在SQL中更新表中的库存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2张不同的桌子
文章
- articlenumber
- 股票
订单
- 订单号
- articlenumber
- 收到的货物
我想用表格订单中收到的货物增加表格中的库存,我该如何管理?
我正在使用apex / oracle
I have 2 differen tables
Article
- articlenumber
- stock
Order
- ordernumber
- articlenumber
- received goods
I want to increment my stock in table Article with the received goods from table order, how can I manage this?
I am using apex/oracle
推荐答案
如果我没错,下面的查询应该可以胜任:
If i'm not wrong, below query should do the job:
UPDATE Article t1 SET stock = (SELECT [received goods] AS stock FROM [Order] t2 WHERE t2.articlenumber = t1.articlenumber)
强烈建议更改 Order <的名称/ code>表,因为它是 Oracle数据库的保留字之一 [ ^ ] !你可以改用
Orders
。
It's strongly recommended to change the name of Order
table, because it is one of reserved words of Oracle database[^]! You can use Orders
instead.
UPDATE A SET A.stock=B.receivedgoods FROM Article A
INNER JOIN Order B
ON A.articlenumber=B.articlenumber
这篇关于使用2个表时,如何在SQL中更新表中的库存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文