RageMasterGaming
RageMasterGaming

Reputation: 77

How do I sort the sql select statement so it displays the leaderboard correctly?

I have a problem when selecting and grouping the following table. The table "Igralci" looks like this:

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

I would like to sort the id's in the following way:

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

I tried:

Select * from Igralci 
group by id, st_tock, st_srecanj, st_nizov, st_gemov
order by st_tock, st_srecanj, st_nizov, st_gemov;

The wanted display would be (ID's):

  1. 15 ( same st_tock and st_srecanj as 11 but he has more st_nizov)
  2. 11
  3. 19

Upvotes: 0

Views: 61

Answers (1)

SteveB
SteveB

Reputation: 924

You need to add "Desc" or "asc" to your order by clause to get the results you want. Based on the output you provided, you need to add "Desc" after each column in the order by

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;

Upvotes: 1

Related Questions