Reputation: 843
is there a possible way to sort the number with something below
GameID Turn
3 2
6 1
7 2
5 2
8 0
9 1
return should be { for example GameID 6 is TURN for the Game or Left in the Game }
GameID Turn
6 1
9 1
8 0
3 2
5 2
7 2
another example { for example GameID 7 is TURN for the Game or Left in the Game }
GameID Turn
7 2
3 2
5 2
8 0
9 1
6 1
that was just a sample that i need to figure out. Is that possible to sort the Turn?
I can't use the ORDER BY turn DESC/ASC
Because what order by doing is just something like this 2 1 0
while ASC 0 1 2
bu what i need to figure out is that to sort this way { we have 0 1 2 } now if we starts at 2
then the sort should be something like this 2 0 1
or if we starts at turn 1 the sorts should be this way 1 2 0
i hope something get my point...
please i already used asort but its not fit. is there any other php function for sorting?
thanks...
Upvotes: 0
Views: 412
Reputation: 65274
SELECT
GameID,Turn
FROM yourtableorview
WHERE yourcriteria
ORDER BY IF(Turn<$startturn,Turn+99999999,Turn)
Upvotes: 0
Reputation: 152226
You can try with ORDER BY FIELD
:
SELECT *
FROM table
ORDER BY FIELD(Turn, 1, 0, 2) ASC
-- DESC
Upvotes: 2