我有一张这样的表:
"id" "UserName" "score"
"1" "User 1" "2"
"2" "User 2" "5"
"3" "User 3" "3"
"4" "User 4" "7"
"5" "User 5" "1"
并运行这样的SQL:
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"
这一切都来自于分页系统,我们根据分数显示用户。
答案 0 :(得分:1)
您可以在LIMIT中使用偏移:
select userName from stack where id >= 1 order by score DESC LIMIT 3,3
对于您的分页,您必须增加每页的偏移量。