MySQL query to divide column by 100?

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable
   (
   Number float
   );
Query OK, 0 rows affected (0.47 sec)

Insert records in the table using insert command −

mysql> insert into DemoTable values(1000);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(1);
Query OK, 1 row affected (0.27 sec)
mysql> insert into DemoTable values(10);
Query OK, 1 row affected (0.30 sec)
mysql> insert into DemoTable values(100);
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable values(390);
Query OK, 1 row affected (0.09 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output−

+--------+
| Number |
+--------+
| 1000   |
| 1      |
| 10     |
| 100    |
| 390    |
+--------+
5 rows in set (0.00 sec)

Following is the query to divide column by 100−

mysql> update DemoTable set Number=Number/100;
Query OK, 5 rows affected (0.09 sec)
Rows matched: 5 Changed: 5 Warnings: 0

Let us display table records once again −

mysql> select * from DemoTable;

This will produce the following output −

+--------+
| Number |
+--------+
| 10     |
| 0.01   |
| 0.1    |
| 1      |
| 3.9    |
+--------+
5 rows in set (0.00 sec)
raja
Updated on 30-Jul-2019 22:30:26

Advertisements