使用WHERE进行设置,可以获得比特定分数更多的学生记录。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(100), -> StudentScore int -> ); mysql> insert into DemoTable(StudentName,StudentScore) values('Sam',48); mysql> insert into DemoTable(StudentName,StudentScore) values('Chris',33); mysql> insert into DemoTable(StudentName,StudentScore) values('Robert',89);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+----+-------------+--------------+ | Id | StudentName | StudentScore | +----+-------------+--------------+ | 1 | John | 43 | | 2 | Sam | 48 | | 3 | Chris | 33 | | 4 | Robert | 89 | +----+-------------+--------------+ 4 rows in set (0.00 sec)
以下是查询以获取分数超过45分的学生的记录-
mysql> select StudentName from DemoTable where StudentScore > 45;
输出结果
这将产生以下输出-
+-------------+ | StudentName | +-------------+ | Sam | | Robert | +-------------+ 2 rows in set (0.00 sec)