How can I calculate rank based on highest points and lowest time in SQL server -
I searched and searched but they are unable to work. I really appreciate it if someone helped me Can do.
I have a table that stores information for the game played (small quiz application.) I should be able to determine the top 5 ranks, but having the highest score, the shortest time after. (Many players have a maximum score) I need to rank users at any time.
Here is a sample of Game Table: I am using an existing query: (as you can see from the query, the alias is actually stored in the users' table.) I thought Was that this query was working because it showed the right result Was getting, but now that the site is live, and I have thousands of games, I can see that this is wrong. The above question originally gives me 5 players the highest possible score, but it ranks them at their lowest play time Please tell me that I How can I modify / modify or rewrite it completely? (Note, I can make it very easy using php with a loop, but it will not be very efficient.) I am happy to provide more information when I need it. Thank you in advance, Aaron. After the user_ranked_games (user_id selection, credits, user_id) by the user_id command (more than the credit from the division), the text after I Successfully tested the above A. I have modified the values of data so that at least 2 of the top 5 digits. But my query above correctly lists at least once in the top 5 players' ranks. / P> Note - My original SQL Bella has duplicate user rules (I did not bother to define PK), on which separate output was given, where it was included on. I have fixed data since then Has taken and removes join CTE and it has basically put the most important queries. Update in response to the comment A small revision provides a query that is a user Users can see rank and number: You may want to consider creating a visual that can be easily used to answer both questions: the first query is made: by the rank_users command and choose
up to 5 aliases, user_id, rank () Select (Max's) Credits, as a rank of the game in the order of the minute (time-playing), where the user is games.User_ID = User.id and User.ID <20> Games credits & User group by group 0, alias
as user_ranked_games (select user_id, credit, time_played, ROW_NUMBER () (split credit desc from user_id command, time_played ASC) As in the game by game_rank), as ranked by rank_users (, order g.credits desc by g.time_played asc) (ranked as rank (selection), g.user _id, u.alias, g.credits, user_ranked_games from g.time_played users join g.user_id = u.user_id where g.game_rank = 1) * from ranked_users where user_id = 93
view as user_ranked_games In order to select users (user_id, credit, time-Row_number () over (game of credit description, time_played ASC) from game_rank ), Select the rank () (rank more than g.credits desc, g.time_played asc) rank, g.user_id, u.alias, g.credits, split from user_id command, G.time_played user_ranked_games G users can join u g.user_id = u.user_id where g.game_rank = 1
Select the top 5 * by rank
from Rank_source * where user_id = 93
Comments
Post a Comment