繁体   English   中英

如何在MySQL中通过具有某些前缀的该行的自动增量值更新该行的特定字段(列)?

[英]how to update a specific field(column) of a row by that row's autoincrement value with some prefix in mysql?

我有下表

  it_id     item_id     item_name   
    1   ite_1            shirt
    2   ite_10           pant
    3   ite_11           socks
    4   ite_12           shoes
    5   ite_13            belt

现在我需要使用ite_(value of it_id of that row)来更改item_id

表示if it_id=x then item_id should be ite_x ,依此类推...

b sql将为此查询什么?

更新###

如果我想用前缀更改it_id意味着新的it_id=ite_x where x is it's(it_id's) previous value (1,2,3,4,5等...),并且it_id不是自动递增字段

update table_name SET item_id=CONCAT('ite_', id)

对不起,您的列ID为it_id,因此应该为(不确定)

update table_name SET item_id=CONCAT('ite_', it_id)

我认为您可以按照以下步骤进行操作
1]将it_id的数据类型更改为VARCHAR
2]您的查询是

update table_name SET it_id=CONCAT('ite_', it_id)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM