70
Views
2
Comments
High Scores Table
Question

I'm making an application that calculates the score of an user and places this in a highscores table. Now the problem is I can't really find a way to make the ranking work. At the moment this is my query: 

So what it should do is give the user a ranking based on the score they got. Also if 2 users share the same score they should also share the same ranking.


Any help would be appreciated, thanks :)

2011-06-15 10-52-46
Miguel Ribeiro

What's exactly the issue? Is it repeating the rank if the total is the same?

For that I guess the assignment of [Ranking] must be calculated using a subquery to decide whether it must be incremented or not.

2025-09-25 22-50-38
Hanno

You can work through the example here: https://docs.microsoft.com/en-us/sql/t-sql/functions/ranking-functions-transact-sql

Both RANK() and DENSE_RANK() should give you what you need, you just need to decide on the order increment you prefer.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.