MySQL Forums
Forum List  »  Newbie

Re: Remove last digit from all data in column
Posted by: Barry Galbraith
Date: November 26, 2017 02:10PM

Is this what you mean?

mysql> show create table tab_a \G
*************************** 1. row ***************************
       Table: tab_a
Create Table: CREATE TABLE `tab_a` (
  `data` int(10) unsigned NOT NULL,
  `i` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`i`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> select * from tab_a order by i;
+---------+---+
| data    | i |
+---------+---+
|    3741 | 1 |
|   49215 | 2 |
|     345 | 3 |
| 4686794 | 4 |
+---------+---+
4 rows in set (0.02 sec)

mysql> UPDATE tab_a SET DATA = FLOOR(DATA/10);
Query OK, 4 rows affected (0.03 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> select * from tab_a order by i;
+--------+---+
| data   | i |
+--------+---+
|    374 | 1 |
|   4921 | 2 |
|     34 | 3 |
| 468679 | 4 |
+--------+---+
4 rows in set (0.00 sec)

mysql>

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: Remove last digit from all data in column
November 26, 2017 02:10PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.