'How do I find record above and below based on rank
I have a table called scoreboard and I want to fetch two player above and below based on rank for the arbitrary player.
For example, The given table contains the name and rating.
| name | rating |
|---|---|
| Captain | 2100 |
| Ninja | 1300 |
| Mango | 1760 |
| Steve | 1100 |
| Benny | 899 |
| Zeus | 800 |
| Zeprus | 1200 |
For a given player Zephrus, I need to show below records. Two above him and two below.
| rank | name | rating |
|---|---|---|
| 2 | Mango | 1760 |
| 3 | Ninja | 1300 |
| 4 | Zeprus | 1200 |
| 5 | Steve | 1100 |
| 6 | Benny | 899 |
How can I achieve this? I got to know how to find rank using the rank window function in PostgreSQL but not sure how do I achieve two above and two below for a given player effectively.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
