This can be achieved by performing a LEFT JOIN
to the same table on the UserID
column and the Rank
column, plus 1.
The following (simplified) pseudo-code should illustrate how to achieve this:
SELECT R.UserID,
R.Rank,
R1.Diff
FROM Rank R
LEFT JOIN Rank R1 ON R1.UserID = R.UserID AND R1.Rank = R.Rank + 1
Effectively, you are showing the UserID
and Rank
from the current row, but the Diff
erence from the row of the same UserID
with the Rank
+ 1.