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