将列除以 100 的 MySQL 查询?
我们先创建一个表 -
mysql> create table DemoTable ( Number float ); Query OK, 0 rows affected (0.47 sec)
使用插入命令插入记录到表中 -
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)
使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable;
这将产生以下输出 -
+--------+ | Number | +--------+ | 1000 | | 1 | | 10 | | 100 | | 390 | +--------+ 5 rows in set (0.00 sec)
以下是将列除以 100 的查询 -
mysql> update DemoTable set Number=Number/100; Query OK, 5 rows affected (0.09 sec) Rows matched: 5 Changed: 5 Warnings: 0
我们再次显示表格记录 -
mysql> select * from DemoTable;
这将产生以下输出 -
+--------+ | Number | +--------+ | 10 | | 0.01 | | 0.1 | | 1 | | 3.9 | +--------+ 5 rows in set (0.00 sec)
广告