如何通过该行的自动增量值更新该行的特定字段(列)并在mysql中带有一些前缀? [英] how to update a specific field(column) of a row by that row's autoincrement value with some prefix in mysql?

查看:28
本文介绍了如何通过该行的自动增量值更新该行的特定字段(列)并在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 的值)更改 item_id

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

b sql 会为此查询什么??

what will b sql query for that??

如果我想用前缀改变 it_id 意味着new it_id=ite_x 其中 x 是它的(it_id's)以前的值(1,2,3,4,5 等....)并且 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)

这篇关于如何通过该行的自动增量值更新该行的特定字段(列)并在mysql中带有一些前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆