如何使用LIMIT和OFFSET选择所有行,跳过前10行?

huangapple go评论58阅读模式
英文:

How to select all rows, skipping the first 10 by using LIMIT and OFFSET?

问题

Let's assume the table has 110 rows. The following skips the first 10 rows and returns the other 100:

SELECT ... FROM ... ORDER BY ... LIMIT 10, 100

Is there a way to replace 100 by whatever is left?

Desired pseudo-code:

SELECT ... FROM ... ORDER BY ... LIMIT 10, *
英文:

Let's assume the table has 110 rows. The following skips the first 10 rows and returns the other 100:

SELECT ... FROM ... ORDER BY ... LIMIT 10, 100

Is there a way to replace 100 by whatever is left?

Desired pseudo-code:

SELECT ... FROM ... ORDER BY ... LIMIT 10, *

答案1

得分: 2

SELECT语句

要检索从某个偏移量到结果集末尾的所有行,可以使用一个大数作为第二个参数。此语句检索从第96行到最后的所有行:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

英文:

SELECT Statement

>To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:
>
>SELECT * FROM tbl LIMIT 95,18446744073709551615;

答案2

得分: 0

SELECT * FROM TABLE_NAME LIMIT (SELECT count(*) FROM TABLE_NAME) OFFSET 10;

不确定执行时间。

SELECT count(*) FROM TABLE_NAME

这返回可用行数。

英文:
SELECT * FROM TABLE_NAME LIMIT (SELECT count(*) FROM TABLE_NAME) OFFSET 10;

Not sure about the execution time though.

SELECT count(*) FROM TABLE_NAME

This is returning the number of available rows

答案3

得分: 0

只返回翻译好的部分:

从 (
选择 *,行号() Over(按ID ASC排序) RN 从 表
) as vw
其中 RN > 10
英文:
Select * from (
Select *,Row_Number() Over(Order By ID ASC) RN From Table 
) as vw
where RN >10

huangapple
  • 本文由 发表于 2023年4月19日 17:38:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定