如何添加所有产品并在另一个表中更新数据

发布于 2025-01-31 06:04:26 字数 1948 浏览 3 评论 0原文

我有2个表TB1 =存储,tb2 = daily_quota iwant在TB2中添加所有产品,并在表1

示例表 中更新完成的_product table1=storage

product_namefinished_product
Ascorbic Kids30
Ascorbic Adults20

table2=daily_quota

product_namefinished_product
Ascorbic Kids30
Ascorbic Adults30
Ascorbic Kids30
Ascorbic Adults30
Ascorbic Kids30
Ascorbic Adults30

how can i sum all product_name = Ascorbic Kids.finished_product in table2=daily_quota 并更新table1 =存储product_name = ascorbic kids dement_product = table2 = daily_quota中的总和

预期结果表

1 =储存

product_nameprone_name reparoduct
aboduct aboduct abosorbic Kids90
抗坏血球成人90

i have 2 tables tb1=storage and tb2=daily_quota iwant to add all product with the same name in tb2 and update the finished_product in table1

example table
table1=storage

product_namefinished_product
Ascorbic Kids30
Ascorbic Adults20

table2=daily_quota

product_namefinished_product
Ascorbic Kids30
Ascorbic Adults30
Ascorbic Kids30
Ascorbic Adults30
Ascorbic Kids30
Ascorbic Adults30

how can i sum all product_name = Ascorbic Kids.finished_product in table2=daily_quota
and update the table1 =storage product_name = Ascorbic Kids finished_product = value of the sum in table2=daily_quota

expected result

table1=storage

product_namefinished_product
Ascorbic Kids90
Ascorbic Adults90

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离不开的别离 2025-02-07 06:04:26

我建议将table1作为视图,您可以根据需要使用。

该视图看起来像:

CREATE VIEW storage AS
SELECT product_name, SUM(finished_product) as quantity
FROM table2
GROUP BY product_name

I would propose to make table1 a view, that you can use as needed.

The view would look like that:

CREATE VIEW storage AS
SELECT product_name, SUM(finished_product) as quantity
FROM table2
GROUP BY product_name
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文