让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Value int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(40); mysql> insert into DemoTable values(60); mysql> insert into DemoTable values(45); mysql> insert into DemoTable values(85); mysql> insert into DemoTable values(78);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable;
+-------+ | Value | +-------+ | 40 | | 60 | | 45 | | 85 | | 78 | +-------+ 5 rows in set (0.00 sec)
以下是在MySQL中查找第N个最大值的查询-
mysql> select * from DemoTable order by Value desc limit 2,1;
这将产生以下输出-
+-------+ | Value | +-------+ | 60 | +-------+ 1 row in set (0.00 sec)