如何对sql select语句进行排序,以便正确显示排行榜?

时间:2017-07-14 16:34:33

标签: mysql sql select group-by leaderboard

选择和分组下表时出现问题。 表" Igralci"看起来像这样:

{
   "errorMessage": "RequestId: 6737e0a4-68af-11e7-8ab8-7fb105ccffaacc Process exited before completing request"
}

我想按以下方式对id进行排序:

----------------------------------------------
|ID|U_ID|st_tock|st_srecanj|st_nizov|st_gemov|
----------------------------------------------
|19| 17 |   6   |     3    |   6    |   72   |
----------------------------------------------
|11| 19 |  12   |     6    |   24   |   144  |
----------------------------------------------
|15| 18 |  12   |     6    |   26   |   72   |
----------------------------------------------

我试过了:

1. First looks at st_tock (if st_tock is same) ->
2. Looks at st_srecanj (if st_srecanj is same) ->
3. Looks at st_nizov (if st_nizov is same) ->
4. Looks at st_gemov

想要的显示是(ID' s):

  1. 15(与st_tock和st_srecanj相同,但是他有更多的st_nizov)
  2. 11
  3. 19

1 个答案:

答案 0 :(得分:1)

你需要添加" Desc"或" asc"到你的order by子句来获得你想要的结果。根据您提供的输出,您需要添加" Desc"在

之后的每一列之后
Select * from Igralci 
group by id, st_tock, st_srecanj, st_nizov, st_gemov
order by st_tock desc, st_srecanj desc, st_nizov desc, st_gemov desc;