Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql坚持按描述和限制订购_Mysql_Sql - Fatal编程技术网

Mysql坚持按描述和限制订购

Mysql坚持按描述和限制订购,mysql,sql,Mysql,Sql,我有一张这样的桌子: "id" "UserName" "score" "1" "User 1" "2" "2" "User 2" "5" "3" "User 3" "3" "4" "User 4" "7" "5" "User 5" "1" select userName from stack where id >= 0 order by score DESC LIMIT 3 并运行如下sql: "id"

我有一张这样的桌子:

"id"    "UserName"  "score"
"1"     "User 1"    "2"
"2"     "User 2"    "5"
"3"     "User 3"    "3"
"4"     "User 4"    "7"
"5"     "User 5"    "1"
select userName from stack where id >= 0 order by score DESC LIMIT 3
并运行如下sql:

"id"    "UserName"  "score"
"1"     "User 1"    "2"
"2"     "User 2"    "5"
"3"     "User 3"    "3"
"4"     "User 4"    "7"
"5"     "User 5"    "1"
select userName from stack where id >= 0 order by score DESC LIMIT 3
这就是结果

"userName"
"User 4"
"User 2"
"User 3"
也就是说它是这样安排的

"id"    "UserName"  "score"
"4"     "User 4"    "7"
"2"     "User 2"    "5"
"3"     "User 3"    "3"
"1"     "User 1"    "2"
"5"     "User 5"    "1"
我如何从id 1开始,得到如下结果。因为无论我做什么,我总是得到错误的结果:

预期结果:

select userName from stack where id >= 1 order by score DESC LIMIT 3

"1" "User 1"    "2" /*These are my expected results and not what the above query outputs*/
"5" "User 5"    "1"

这一切都来自分页系统,我们使用该系统根据用户的分数显示用户。

您可以在限制中使用偏移量:

select userName from stack where id >= 1 order by score DESC LIMIT 3,3

对于分页,您必须增加每页的偏移量。

如果用户1(id 1)没有最高分数(按分数顺序描述),为什么要从用户1开始?如果您希望用户1的分数始终处于第一位,然后是第三位,那么您需要运行2选择并使用UNION。祝你好运。你想得到下三个吗?在这种情况下,您需要
按分数描述限制3,3从堆栈顺序中选择用户名
@Grim。。。第一组是用户4、2、3。所以下一组将从1开始,所以它将是用户1和5。每页3个结果。4,2,3是第一个,1和5将出现在第2页。我猜,
=1
是相当多余的。那么这里有什么需要不断改变的呢?
后面的第二个数字,
否,第一个数字<代码>限制[偏移量],[返回行]谢谢。这似乎很好。