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中带有一些前缀?
基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
