SQL 查询从一个 table 求和到另一个

SQL query for summing from one table into another

我有两个表:

我需要的是 SQL 查询,我可以通过 phpMyAdmin 中的 SQL 选项卡 运行,它将对“[=25] 中的“options_stock”求和=]”基于“product_id”,它会将相应的“product_id”的和数写入“table_products”中的“main_stock”,因此“table_products”将如下所示:

提前致谢。

尝试以下 - 更新加入

update table_product p  
join 
(select product_id, sum(options_stock) as options_stock from
table_options group by product_id
) o on p.product_id=o.product_id
set main_stock=options_stock