how to update a specific field(column) of a row by that row#39;s autoincrement value with some prefix in mysql?(如何通过该行的自动增量值更新该行的特定字段(列)并在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中带有一些前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过该行的自动增量值更新该行的特定字段(列)并在mysql中带有一些前缀?


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01