在MySQL中两行之间获取数据?
要在两行之间获取数据,请使用LIMIT概念。让我们首先创建一个表-
mysql> create table DemoTable(
Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name varchar(10)
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(Name) values('Larry');mysql> insert into DemoTable(Name) values('Robert');
mysql> insert into DemoTable(Name) values('Chris');
mysql> insert into DemoTable(Name) values('David');
mysql> insert into DemoTable(Name) values('Bob');
mysql> insert into DemoTable(Name) values('Sam');
mysql> insert into DemoTable(Name) values('Mike');
mysql> insert into DemoTable(Name) values('Carol');
mysql> insert into DemoTable(Name) values('John');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+--------+| Id | Name |
+----+--------+
| 1 | Larry |
| 2 | Robert |
| 3 | Chris |
| 4 | David |
| 5 | Bob |
| 6 | Sam |
| 7 | Mike |
| 8 | Carol |
| 9 | John |
+----+--------+
9 rows in set (0.00 sec)
以下是在两行之间获取数据的查询-
mysql> select *from DemoTable limit 2,3;
这将产生以下输出-
+----+-------+| Id | Name |
+----+-------+
| 3 | Chris |
| 4 | David |
| 5 | Bob |
+----+-------+
3 rows in set (0.00 sec)
以上是 在MySQL中两行之间获取数据? 的全部内容, 来源链接: utcz.com/z/321757.html