从 MySQL 列中提取最大值?
让我们先创建一个表 -
mysql> create table DemoTable -> ( -> Value int -> ); Query OK, 0 rows affected (0.63 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(58); Query OK, 1 row affected (0.25 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
这将生成以下输出 -
+-------+ | Value | +-------+ | 78 | | 89 | | 98 | | 58 | +-------+ 4 rows in set (0.00 sec)
以下是从列中获取最大值的查询 -
mysql> select Value from DemoTable order by Value DESC limit 1;
这将生成以下输出 -
+-------+ | Value | +-------+ | 98 | +-------+ 1 row in set (0.00 sec)
广告