要获得最高值,请使用GREATEST()
方法。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int, -> Value3 int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(100,600,400);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+--------+--------+--------+ | Value1 | Value2 | Value3 | +--------+--------+--------+ | 100 | 600 | 400 | +--------+--------+--------+ 1 row in set (0.00 sec)
以下是获取最大值的查询-
mysql> select greatest(Value1,Value2,Value3) AS HighestFrom1Row from DemoTable;
输出结果
+-----------------+ | HighestFrom1Row | +-----------------+ | 600 | +-----------------+ 1 row in set (0.00 sec)