如何对 sql select 语句进行排序以使其正确显示排行榜?
How do I sort the sql select statement so it displays the leaderboard correctly?
我在选择和分组以下 table 时遇到问题。
table "Igralci" 看起来像这样:
----------------------------------------------
|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 |
----------------------------------------------
我想按以下方式对 ID 进行排序:
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
我试过:
Select * from Igralci
group by id, st_tock, st_srecanj, st_nizov, st_gemov
order by st_tock, st_srecanj, st_nizov, st_gemov;
想要的显示是(ID):
- 15(与 11 相同的 st_tock 和 st_srecanj 但他有更多 st_nizov)
- 11
- 19
您需要将 "Desc" 或 "asc" 添加到您的 order by 子句中以获得您想要的结果。根据您提供的输出,您需要在 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;
我在选择和分组以下 table 时遇到问题。 table "Igralci" 看起来像这样:
----------------------------------------------
|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 |
----------------------------------------------
我想按以下方式对 ID 进行排序:
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
我试过:
Select * from Igralci
group by id, st_tock, st_srecanj, st_nizov, st_gemov
order by st_tock, st_srecanj, st_nizov, st_gemov;
想要的显示是(ID):
- 15(与 11 相同的 st_tock 和 st_srecanj 但他有更多 st_nizov)
- 11
- 19
您需要将 "Desc" 或 "asc" 添加到您的 order by 子句中以获得您想要的结果。根据您提供的输出,您需要在 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;