如何找出 MySQL 中某个特定分数以上学生的记录?
使用 WHERE 设置它并获取分数高于特定分数的学生记录。让我们首先创建一个表 -
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(100), -> StudentScore int -> ); Query OK, 0 rows affected (1.65 sec
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable(StudentName,StudentScore) values('John',43); Query OK, 1 row affected (0.81 sec) mysql> insert into DemoTable(StudentName,StudentScore) values('Sam',48); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName,StudentScore) values('Chris',33); Query OK, 1 row affected (1.50 sec) mysql> insert into DemoTable(StudentName,StudentScore) values('Robert',89); Query OK, 1 row affected (0.27 sec)
使用 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)
广告