让我们首先创建一个表-
mysql> create table DemoTable( Marks int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(78); mysql> insert into DemoTable values(88); mysql> insert into DemoTable values(67); mysql> insert into DemoTable values(76); mysql> insert into DemoTable values(98); mysql> insert into DemoTable values(86); mysql> insert into DemoTable values(89); mysql> insert into DemoTable values(99);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+ | Marks | +-------+ | 78 | | 88 | | 67 | | 76 | | 98 | | 86 | | 89 | | 99 | +-------+ 8 rows in set (0.00 sec)
以下是从MySQL表中获取第二大标记的查询-
mysql> select Marks from DemoTable where Marks=(select MAX(Marks) from DemoTable where Marks < (select MAX(Marks) from DemoTable));
这将产生以下输出-
+-------+ | Marks | +-------+ | 98 | +-------+ 1 row in set (0.03 sec)