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中带有一些前缀?


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- SQL 临时表问题 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01