gpt4 book ai didi

php - 如何跳过 SQL 查询中的一行?

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:24 24 4
gpt4 key购买 nike

我列出了我的数据库中的产品,我在其中选择了最新的产品作为主要功能。其余按最新产品排序。

所以我有两个查询,看起来像这样。

SELECT * FROM products ORDER BY product_id DESC LIMIT 1

SELECT * FROM products ORDER BY product_id DESC LIMIT 4

但是...这使得最新产品在我当前的布局中出现了两次。 (功能)。

如何让第二个查询跳过最新条目?

最佳答案

我们可以指定 LIMIT 子句改为从第二行开始,然后获取接下来的 4 行。

SELECT * FROM products ORDER BY product_id DESC LIMIT 1,4

Syntax是:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.

The offset of the initial row is 0 (not 1):

关于php - 如何跳过 SQL 查询中的一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53544054/

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