Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KresimirKoncicNeuralab/8037090 to your computer and use it in GitHub Desktop.
Save KresimirKoncicNeuralab/8037090 to your computer and use it in GitHub Desktop.
DECLARE @Rn int;
DECLARE @RnStart int;
DECLARE @RnEnd int;
DECLARE @Increment int = 5;
DECLARE @PlayerId int = 10;
Select @Rn = tt.RowNo FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY PlayerScore desc) as RowNo from Players) tt WHERE tt.PlayerId = @PlayerId;
SET @RnStart = @Rn-@Increment;
SET @RnEnd = @Rn+@Increment;
Select t.RowNo, t.PlayerName, t.PlayerId , t.PlayerScore, t.PlayerTime from ( Select *, ROW_NUMBER() OVER (ORDER BY PlayerScore desc) as RowNo from Players ) t where t.RowNo between @RnStart AND @RnEnd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment