gpt4 book ai didi

mysql - 根据条件插入

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:57 25 4
gpt4 key购买 nike

我想在 mysql 表中插入一些数据。我在 opencart 中有一个 option_id = 6 的选项,我想在所有包含 option_id=6 的产品中插入一个 option_id=9 的新选项。

 insert into oc_product_option (`option_id`)
select 9
where (SELECT `option_id` FROM oc_product_option WHERE `option_id` == 6);

不工作。我们如何给出在 opencart 中执行此操作的条件?

编辑:这里有更多信息。我有一个选项颜色 1,它已经分配给了数千种产品。我正在尝试将颜色 2 分配给所有包含颜色 1 的产品。

  1. Color1- 选项 id = 6
  2. color2- 选项 id = 9

在 opencart 中,mysql 数据库表是 oc_product_option 和 oc_product_option_value。

在 oc_product_option 中,我们有字段 product_id、product_option_id(自动增量-无需更新)、option_id

所以我正在做的是选择颜色 2 -9 的选项 id 并分配给选项 id = 6 的产品

最佳答案

如果我做对了,你的查询一定是这样的:

INSERT INTO oc_product_option (`product_id`,`option_id`)
SELECT product_id,9
FROM oc_product_option
WHERE `option_id` = 6;

关于mysql - 根据条件插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29949657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com