让我们首先创建一个表-
mysql> create table DemoTable ( Score int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(45); mysql> insert into DemoTable values(29); mysql> insert into DemoTable values(56); mysql> insert into DemoTable values(24); mysql> insert into DemoTable values(32);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+ | Score | +-------+ | 45 | | 29 | | 56 | | 24 | | 32 | +-------+ 5 rows in set (0.00 sec)
以下是通过减去某些条件下的值来更新MySQL列的查询-
mysql> update DemoTable set Score=Score-2 where Score > 30; Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+ | Score | +-------+ | 43 | | 29 | | 54 | | 24 | | 30 | +-------+ 5 rows in set (0.00 sec)