gpt4 book ai didi

MySQL 选择 * Where NUM_ROW > X

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:41 26 4
gpt4 key购买 nike

我有表客户

+------+------+------------+
| 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";

关于MySQL 选择 * Where NUM_ROW > X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48495042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com