如何从数据库中使用当前值减去旧值?
我的问题是我有2张桌子。假设表旧
和表当前
。这两个表都有列数量
。 old.quantity
是旧值,current.quantity
是当前值。
表旧:
id pro.no Quantity
1 123 3
表当前:
id pro.no Quantity
1 123 2
sql:
SELECT A.`Quantity`, B.`Quantity`
FROM Table Current A
LEFT JOIN Table Old B ON B.`pro.no` = A.`pro.no`
WHERE A.`id` = '1'
所以,我想减去两个值以获取1
的新值,以便在pro.no中的用户键
中textbox
,它将向他们展示它们的新值Quantity
is 1
。
我正在为后端使用vb.net
,但我仍然对此语言使用。
my question is I have 2 tables. let say Table Old
and Table Current
. Both tables have columns Quantity
. Old.Quantity
is the old values, and Current.Quantity
is the current values.
Table Old :
id pro.no Quantity
1 123 3
Table Current :
id pro.no Quantity
1 123 2
SQL :
SELECT A.`Quantity`, B.`Quantity`
FROM Table Current A
LEFT JOIN Table Old B ON B.`pro.no` = A.`pro.no`
WHERE A.`id` = '1'
So, I want to subtract both values to get the new values which is 1
So that, when user key in the pro.no
into the textbox
, it'll show them they new value for Quantity
is 1
.
I am using VB.NET
for the backend, and I'm still new for this language too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地减去这两个列,但是由于这是一个左联接,您需要照顾零值:
或替代
You can simply subtract both columns, however as this is a left join you'll need to care for the null values:
or alternatively