MySQL 查询可减少特定值的 10?
让我们先创建一个表 -
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score int ); Query OK, 0 rows affected (0.89 sec)
使用 insert 命令向表中插入一些记录 -
mysql> insert into DemoTable(Score) values(67); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Score) values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Score) values(90); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Score) values(56); Query OK, 1 row affected (0.13 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
输出
+----+-------+ | Id | Score | +----+-------+ | 1 | 67 | | 2 | 78 | | 3 | 90 | | 4 | 56 | +----+-------+ 4 rows in set (0.00 sec)
以下是减少某个特定值 10 的查询 -
mysql> update DemoTable set Score=Score-10 where Id=3; Query OK, 1 row affected (0.38 sec) Rows matched : 1 Changed : 1 Warnings : 0
让我们再次检查一下表记录 -
mysql> select *from DemoTable;
输出
+----+-------+ | Id | Score | +----+-------+ | 1 | 67 | | 2 | 78 | | 3 | 80 | | 4 | 56 | +----+-------+ 4 rows in set (0.00 sec)
广告