我有表客户
+------+------+------------+
| id | name | company_id |
+------+------+------------+
| 1 | Test | 1 |
+------+------+------------+
当我想选择(例如)前 30 个客户端时,没问题。
SELECT
id,
name
FROM client
WHERE company_id = 1
LIMIT 30;
但我现在不会选择第二个 30、第三个 30。我的解决方法:
SET @row_num=0
SELECT
@row_num:=@row_num+1 AS row_number,
id,
name
FROM client
WHERE company_id = 1
AND row_number = 20;
LIMIT 30;
存在错误:“where 子句”中的未知列“row_number”。如何解决?
查看LIMIT OFFSET
syntax
What if we want to select records 16 - 25 (inclusive)?
Mysql also provides a way to handle this: by using OFFSET.
The SQL query below says "return only 10 records, start on record 16 (OFFSET 15)":
$sql = "SELECT * FROM Orders LIMIT 10 OFFSET 15";
我是一名优秀的程序员,十分优秀!