为此,请使用BETWEEN关键字。让我们首先创建一个表-
mysql> create table DemoTable1537 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1537(StudentName) values('Chris'); mysql> insert into DemoTable1537(StudentName) values('Bob'); mysql> insert into DemoTable1537(StudentName) values('Sam'); mysql> insert into DemoTable1537(StudentName) values('Mike'); mysql> insert into DemoTable1537(StudentName) values('David'); mysql> insert into DemoTable1537(StudentName) values('John'); mysql> insert into DemoTable1537(StudentName) values('Carol');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1537;
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Bob | | 3 | Sam | | 4 | Mike | | 5 | David | | 6 | John | | 7 | Carol | +-----------+-------------+ 7 rows in set (0.00 sec)
以下是显示多个输入值的查询-
mysql> select StudentName from DemoTable1537 where StudentId between 3 and 6;
这将产生以下输出-
+-------------+ | StudentName | +-------------+ | Sam | | Mike | | David | | John | +-------------+ 4 rows in set (0.00 sec)