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中带有一些前缀?
基础教程推荐
- oracle区分大小写的原因? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在多列上分布任意行 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
