更新时间:2023-01-28 19:52:19
在 SQL 中,您可以使用 union
all 来做到这一点,首先得到分数较高或相等的 11 行,然后分数较低的 10 行:
In SQL, you can do this with a union
all, first to get the 11 rows with higher or equal scores and then the 10 rows with lower scores:
(select s.*
from scores s
where s.score >= (select max(score) from scores where user = $USER)
order by s.score asc
limit 11
)
union all
(select s.*
from scores s
where s.score <= (select max(score) from scores where user = $USER) and users <> $USER
order by s.score desc
limit 10
)