让我们首先创建一个表-
mysql> create table DemoTable1614 -> ( -> StudentName varchar(20), -> StudentScore int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1614 values('Adam',65); mysql> insert into DemoTable1614 values('Chris',89); mysql> insert into DemoTable1614 values('Bob',58); mysql> insert into DemoTable1614 values('Sam',98); mysql> insert into DemoTable1614 values('Mike',87); mysql> insert into DemoTable1614 values('Carol',79);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1614;
这将产生以下输出
+-------------+--------------+ | StudentName | StudentScore | +-------------+--------------+ | Adam | 65 | | Chris | 89 | | Bob | 58 | | Sam | 98 | | Mike | 87 | | Carol | 79 | +-------------+--------------+ 6 rows in set (0.00 sec)
这是查询以获得3个具有较高值的记录-
mysql> select * from DemoTable1614 order by StudentScore DESC LIMIT 3;
这将产生以下输出
+-------------+--------------+ | StudentName | StudentScore | +-------------+--------------+ | Sam | 98 | | Chris | 89 | | Mike | 87 | +-------------+--------------+ 3 rows in set (0.00 sec)