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: Pre-user_id Credit Time-Playing Surname ------- --- ---- -------- --- -------------- 64 490 180 Daplaya 93 690 187 Superman 64 336 187 Dailaya 75 1962 192 Layer 93 182 197 Superman 57 844 198 John Smith 75 350 198 Layer 64 858 384 Daplaya 73 858 400 littleguy 57 858 412 John Smith 101 858 420 Flash 73 858 423 littleguy 73 858 434 littleguy 65 858 460 Sheena 122 858 540 Chinese Queen 126 858 545 Rachel 176 350 2417 Fire Light 157 350 2442 Big Q161 350 2456 JOI Blue

I am using an existing query:

  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 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

desc game as play_rank, time_played ASC), select top rank (rank by g.credits desc, g.time_played AS), g.user_id, u As alias, g.credits, g.time_played users from user_ranked_games have joined g.user_id = u.user_id where g.game_rank = 1 rank by rank

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:

  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   

You may want to consider creating a visual that can be easily used to answer both questions:

  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   

the first query is made:

  Select the top 5 * by rank   

by the rank_users command and choose

  from Rank_source * where user_id = 93    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -