MySQL MySQL限制范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5767479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:37:08  来源:igfitidea点击:

MySQL limit range

mysqlsqlsql-limit

提问by theHack

SELECT name FROM mydb ORDER BY score DESC LIMIT 10;

The query above will return the first 10 ranks.

上面的查询将返回前 10 个等级。

How to modify the LIMIT, or maybe is there another syntax to query the 10th rank through the 20th rank?

如何修改LIMIT,或者是否有另一种语法来查询第 10 位到第 20 位?

回答by James C

This is really basic stuff. You should use:

这真的是基本的东西。你应该使用:

SELECT name FROM mydb ORDER BY score DESC LIMIT 10,10;

http://dev.mysql.com/doc/refman/5.5/en/select.html

http://dev.mysql.com/doc/refman/5.5/en/select.html

The two arguments 10,10 are (Offset, Limit) so this will retrieve rows 11-20.
9,11 Would be required to grab the 10th - 20th rank.

两个参数 10,10 是 (Offset, Limit) 所以这将检索行 11-20。
9,11 将需要获得第 10 到 20 位。

回答by jotapdiez

Use offsetto clarify the query.

使用offset澄清查询。

SELECT name FROM mydb ORDER BY score DESC LIMIT 10 OFFSET 10

回答by Nicola Cossu

Limit has also an offset parameter

限制也有一个偏移参数

SELECT name FROM mydb ORDER BY score DESC LIMIT 10,10

回答by Christo

SET @rank = 0;
SELECT rank, name, score
FROM (
    SELECT @rank := @rank +1 AS rank, name, score
    FROM mydb
    ORDER BY score DESC 
    LIMIT 100 
) X
WHERE rank >= 10;

回答by Parvej Ahmed

you may use offset

你可以使用偏移量

SELECT name FROM mydb ORDER BY score DESC LIMIT 10 OFFSET 10

here, offsetindicates that from where next 10 data will show.

you may also use below :

在这里,偏移量表示接下来 10 个数据将显示的位置。

你也可以在下面使用:

SELECT name FROM mydb ORDER BY score DESC LIMIT 10, 10