我有两个表,一个名为 product_text
,其中包含产品名称、描述和类别。另一个名为 product_price
,其中包含产品 selling_price
和 cost_price
。
我想用通用值更新 product_price
表,例如,cost_price
为 0.01
和 selling_price
作为0.01
对于 product_text
表中存在的每一行,我需要以某种方式将此信息插入到 product_price
表中。
例如,如果我有:
id name description category
1 example example hats
2 example2 example2 socks
在 product_text
表中,我想插入:
id selling_price cost_price
1 0.01 0.01
2 0.01 0.01
进入 product_price
表。
我想对一百万个项目执行此操作,因此需要一种有效的方法。
请帮忙
最佳答案
insert into product_price (id, selling_price, cost_price)
select id, 0.01, 0.01 from product_text
关于MySQL - 如果 id 存在于另一个表中,则插入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13633461/