如何通过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_(该行的 it_id 的值)

表示如果it_id=x那么item_id应该是ite_x等等...

b sql 会查询什么??

what will b sql query for that??

如果我想改变带有前缀的 it_id 意味着new it_id=ite_x where x is it's (it_id's) previous value(1,2,3,4,5 etc..) and it_id 不是自增字段

if i want to change it_id with a prefix means new it_id=ite_x where x is it's(it_id's) previous value(1,2,3,4,5 etc....) and it_id is not an auto increment field

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

抱歉你的列 id it_id,所以它应该是(虽然不确定)

SORRY your column id it_id, so it should be (Not Sure Though)

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

我认为您可以通过以下步骤来完成
1] 将 it_id 的数据类型更改为 VARCHAR
2] 您的查询是

I think you can do it with follwing steps
1] Change datatype of it_id to VARCHAR
2] your query is

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