我有一个这样的表:
"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"
这整个东西来自一个分页系统,我们使用该系统根据用户的分数显示用户
可以在LIMIT:
中使用偏移量select userName from stack where id >= 1 order by score DESC LIMIT 3,3
对于分页,您必须增加每页的偏移量