请帮助我使用 MySql 脚本,我遇到了一个错误。我有一个包含 p_id 和 prod_skuid 字段的表(tbl_products),我想将所有重复的 prod_skuid 更新到我的 tbl_products 中。
这是我的 MySql 脚本:
UPDATE tbl_product t1 SET t1.prod_skuid = t.prod_skuid
(
SELECT p_id, prod_skuid from
(SELECT p_id,if(@row = prod_skuid, @count, @count := 1),
CONCAT(prod_skuid, '', @count) as prod_skuid,
@row := prod_skuid,
@count := @count + 1
from tbl_product JOIN (SELECT @count := 0, @row := "") as t
WHERE prod_skuid IN(SELECT prod_skuid from tbl_product group by prod_skuid having count(prod_skuid) > 1)
) as final
) as t
WHERE t1.p_id = t.p_id
我设法仅使用没有更新脚本的嵌套选择来显示和更改 prod_skuid,但是当我放置更新脚本时,它说我的代码有错误:
SELECT p_id, prod_skuid from
(SELECT p_id,if(@row = prod_skuid, @count, @count := 1),
CONCAT(prod_skuid, '', @count) as prod_skuid,
@row := prod_skuid,
@count := @count + 1
from tbl_product JOIN (SELECT @count := 0, @row := "") as t
WHERE prod_skuid IN(SELECT prod_skuid from tbl_product group by prod_skuid having count(prod_skuid) > 1)
) as final
错误: Mysql 错误信息