I’ve got a table containing results of chess matches:
id | player_white | player_black | result | session_start | session_end |
---|---|---|---|---|---|
1 | Jonathan1 | TrentX | 0 | 2020-01-01 13:10:10 | 2020-01-01 13:15:23 |
2 | TrentX | Jonathan1 | 1 | 2020-01-01 13:18:32 | 2020-01-01 13:23:13 |
3 | Ezekiel2001 | Jonathan1 | 1 | 2020-01-01 13:30:12 | 2020-01-01 13:37:01 |
4 | Ezekiel2001 | TrentX | 3 | 2020-01-01 13:40:08 | 2020-01-01 13:44:02 |
5 | Jonathan1 | Ezekiel2001 | 4 | 2020-01-01 13:48:32 | 2020-01-01 13:53:56 |
6 | TrentX | Ezekiel2001 | 1 | 2020-01-01 13:56:30 | 2020-01-01 13:59:02 |
result
is an enum where:
- 0 = white victory
- 1 = black victory
- 2 = draw by agreement
- 3 = draw by stalemate
- 4 = draw by repetition
- 5 = draw by fifty move rule
- 6 = aborted
I would like to sort players by maximum number of victories and draws to display a leader board. Is there any straightforward way to get this leader board view or are any changes required in the way the data is organized?
2
Answers
You can list the white and black victories along with draws and then apply group by on counts to get the result set.
Please refer below.
Result:
Lacking normalization every condition requires sub-query :