[英]MySQL: Add trailing zero to each row
I have a DB setup with two columns, ID
and VAL
.我有一个包含两列ID
和VAL
的数据库设置。
ID
is an incrementing integer, starting from 1 and increasing by 1 for each row. ID
是一个递增的 integer,从 1 开始,每行递增 1。 VAL
is a simple string. VAL
是一个简单的字符串。
How can I update each row's ID
to be 10 times greater?如何将每行的ID
更新为大 10 倍? Eg: ID 1, 2, 3
-> ID 10, 20, 30
例如: ID 1, 2, 3
-> ID 10, 20, 30
Or is there a better method to adding a trailing zero to the end of every row in a column?或者有没有更好的方法来在一列中的每一行的末尾添加一个尾随零?
If you are trying to update the existing values, you simply need to do:如果您尝试更新现有值,您只需执行以下操作:
update mysterytablename set ID=ID*10 order by ID desc;
(The order by is only needed if ID is a primary or unique key, which presumably it is.) (仅当 ID 是主键或唯一键时才需要 order by,大概是这样。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.