如何使用 MySQL 从一列中的所有值中减去相同的金额?
mysqlmysqli database
首先我们创建一个表 −
mysql> create table DemoTable741 (Number int); Query OK, 0 rows affected (0.61 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable741 values(70); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable741 values(55); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable741 values(89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable741 values(79); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable741 values(34); Query OK, 1 row affected (0.17 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable741;
这将产生以下输出 -
+--------+ | Number | +--------+ | 70 | | 55 | | 89 | | 79 | | 34 | +--------+ 5 rows in set (0.00 sec)
以下查询从一列的所有值中减去相同的金额 −
mysql> select (Number-20) AS Result from DemoTable741;
这将产生以下输出 -
+--------+ | Result | +--------+ | 50 | | 35 | | 69 | | 59 | | 14 | +--------+ 5 rows in set (0.00 sec)