MySQL order by two values

In short, I have a game, and the scoreboard for it shows the player’s score at the end + how much time they took to reach it. I need to order my MySQL results so that the highest score is the first at the fastest time, and the lowest score with the slowest time is the last, and everything in between is rated the same. But I have no idea how I will do this, here is my sql as it stands:

$sql1 = "SELECT * FROM boobmatch_highscores ORDER BY t_score DESC, time ASC"; 

Any help would be greatly appreciated!

The data in the table:

 Score Time 23 00:04:32 23 00:04:31 25 00:02:32 16 00:06:32 35 00:04:32 2 00:01:17 -13 00:19:32 -3 00:07:27 
+4
source share
6 answers

Your request should work perfectly. If you have any questions, just insert the field names in quotation marks as follows:

 $sql1 = "SELECT * FROM boobmatch_highscores ORDER BY `t_score` DESC, `time` ASC"; 

Guess it MySQL, otherwise quotes will not be needed

+8
source

you should use an integer column for time instead of varchar,
which means the conversion 00:19:32 is only 1172 seconds,
it's pretty easy to sort

0
source

You should use the code below. His job.

 $query = "SELECT field1, field2 from tablename ORDER BY field1 DESC, field2 DESC"; 
0
source

I think this is the best solution for ordering multiple values.

  SELECT * FROM hotel WHERE confId=13 GROUP BY hotelName ORDER BY CASE WHEN rating = '5 Star' THEN 1 WHEN rating = '4 Star' THEN 2 WHEN rating = '3 Star' THEN 3 WHEN rating = 'BUDGET & EQUIVALENT HOTELS' THEN 4 END 
0
source

You should use this query:

 select * from boobmatch_highscores order by time ASC, t_score DESC 

Now the time is displayed in ascending order, and the score is displayed in descending order.

0
source

just try

 $sql1 = "SELECT * FROM boobmatch_highscores ORDER BY t_score * time DESC"; 
-2
source

Source: https://habr.com/ru/post/1415372/


All Articles