0

我有竞争表结构:

user_id | score

我需要在(例如)user_id=20 之前获取 2 行信息,在显示排名表之后获取 2 行信息。

我想要这个分数表的结果:

order | user_id | score
   23 | XY1     |   240
   24 | XY1     |   247
   25 | 20      |   250 (my specific row)
   26 | XY1     |   252
   27 | XY1     |   290
4

1 回答 1

1
with aaa as
(
SELECT  
ROW_NUMBER() OVER (ORDER BY score ) AS 'ROW_NUMBER', score, user_id
)

select * from aaa where ROW_NUMBER between
(select ROW_NUMBER-2 from aaa where user_id = 25) AND
(select ROW_NUMBER+2 from aaa where user_id = 25)
于 2013-07-29T07:50:53.037 回答