且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过主键选择一行,在“上方"选择一行,在另一列“下方"选择一行?

更新时间:2022-06-09 22:19:30

首先,查询该特定用户的分数:

First, query the score for that particular user:

select  score
from    users
where   id = 42

说用户42的得分是6.您可以查询下一个用户,例如:

Say the score for user 42 is 6. You can then query the next user like:

select  name
,       score
from    users
where   score > 6
order by
        score
limit   1

和以前的用户类似:

select  name
,       score
from    users
where   score < 6
order by
        score desc
limit   1