Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7128643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:09:35+00:00 2026-05-28T11:09:35+00:00

This has me stumped. This is quite a simplified version but let’s say I

  • 0

This has me stumped. This is quite a simplified version but let’s say I have a league table of users in SQL Server such as:

UserId Total  
1       10  
2        5  
3       20  
4        3  
5       40  
6       15  
7       22  
8        1  
9       18  
10      33

Now I can easily order this to be by total like so:

Position  UserId  Total  
1            5      40  
2           10      33  
3            7      22   
4            3      20   
5            9      18   
6            6      15  
7            1      10  
8            2       5  
9            4       3   
10           8       1  

But I would also like to display a particular users position in the table and the two above and below like so for user 1 who is seventh:

Position UserId  Total  
5           9      18   
6           6      15  
7           1      10  
8           2       5  
9           4       3  

I hope this makes sense and any help/insight would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:09:36+00:00Added an answer on May 28, 2026 at 11:09 am

    You could try:

    SELECT * FROM
      (SELECT ROW_NUMBER() OVER (ORDER BY Total DESC) AS Position, 
              UserId, 
              Total
       FROM your_table) p
    WHERE p.Position BETWEEN desiredId-2 AND desiredId+2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This really has my stumped today. I'm sure its simple, but... Here is my
This one has me stumped. I've got a java.sql.ResultSet and I'm pulling string values
I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on
I don't know if anyone has seen this issue before but I'm just stumped.
I'm new to Ajax and this has me stumped. It's relatively simple but trips
I'm quite stumped on this issue. I have a large library of H.264 mp4
I'm not sure why this has stumped me. I have the following code $website
I have quite a bit of experience with css and even this problem has
Finding a good way to do this has stumped me for a while now:
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.