从单个 MySQL 列值减去一个数字?
只需更新表格并减去即可。我们首先创建一个表格 -
mysql> create table DemoTable1372 -> ( -> Value int -> ); Query OK, 0 rows affected (0.77 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable1372 values(500); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1372 values(100); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1372 values(900); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1372 values(1000); Query OK, 1 row affected (0.32 sec)
使用 select 语句显示表中的所有记录 -
mysql> select * from DemoTable1372;
这将产生以下输出 -
+-------+ | Value | +-------+ | 500 | | 100 | | 900 | | 1000 | +-------+ 4 rows in set (0.00 sec)
以下查询可从单个 MySQL 列值减去一个数字 -
mysql> update DemoTable1372 set Value=Value-50 where Value=900; Query OK, 1 row affected (0.52 sec) Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录 -
mysql> select * from DemoTable1372;
这将产生以下输出 -
+-------+ | Value | +-------+ | 500 | | 100 | | 850 | | 1000 | +-------+ 4 rows in set (0.00 sec)
广告