MySQL order by two values

前端 未结 6 1884
清酒与你
清酒与你 2021-01-19 02:43

In short, I have a game of sorts, and the score board for it shows the score of the player at the end + how long they took to achieve it. I need to order my MySQL results so

相关标签:
6条回答
  • 2021-01-19 03:08

    You should be use below code.. Its working.

    $query = "SELECT field1, field2 from tablename ORDER BY field1 DESC, field2 DESC";
    
    0 讨论(0)
  • 2021-01-19 03:11

    you should use an integer column for time instead of a varchar,
    that's mean convert 00:19:32 to just 1172 seconds,
    then is pretty easy for sort

    0 讨论(0)
  • 2021-01-19 03:21

    I think this is the best solution for arrange order by multiple value.

     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 讨论(0)
  • 2021-01-19 03:21

    just try

    $sql1 = "SELECT * FROM boobmatch_highscores ORDER BY t_score * time DESC";
    
    0 讨论(0)
  • 2021-01-19 03:26

    You query is supposed to work perfectly. If you have any issues just enclose the field names in quotes like so:

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

    Guessing it's MySQL, else the quotes won't be necessary

    0 讨论(0)
  • 2021-01-19 03:34

    You've to use this query:

    select * from boobmatch_highscores order by time ASC, t_score DESC
    

    Now time is displayed ascending order and score is displayed descending order.

    0 讨论(0)
提交回复
热议问题