让我们首先创建一个表-mysql> create table DemoTable
(
Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Number int
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable(Number) values(10);
mysql> insert into DemoTable(Number) values(50);
mysql> insert into DemoTable(Number) values(100);
mysql> insert into DemoTable(Number) values(190);
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
这将产生以下输出-+----+--------+
| Id | Number |
+----+--------+
| 1 | 10 |
| 2 | 50 |
| 3 | 100 |
| 4 | 190 |
+----+--------+
4 rows in set (0.00 sec)
以下是要greatest()在MySQL中更新的查询-mysql> update DemoTable set Number=GREATEST(200,Number) WHERE Id=3;
Rows matched: 1 Changed: 1 Warnings: 0
让我们再次显示表记录-mysql> select *from DemoTable;
这将产生以下输出-+----+--------+
| Id | Number |
+----+--------+
| 1 | 10 |
| 2 | 50 |
| 3 | 200 |
| 4 | 190 |
+----+--------+
4 rows in set (0.00 sec)