Answer the question
In order to leave comments, you need to log in
How to sort a MYSQL column in this way?
There are tables people of the form
name | number
Ivan | 125
Peter | 250
oleg | 105
nastya | 303
fedora | 0
sleigh | 125
vlad | 0
ruslan | 401
maxims | 236
olya | 148
oksana | 0
you need to sort it in such a way that the sorting would go first by the first digits, then by the last two digits from smallest to largest, and with 0 were at the very end.
It should look like this
name | number
oleg | 105
Ivan | 125
sleigh | 125
Olya | 148
maxims | 236
Peter | 250
nastya | 303
ruslan | 401
fedora | 0
vlad | 0
oksana | 0
and here is the sorting - only by the last 2 digits, zeros at the end
name | number
oleg | 105
ruslan | 401
nastya | 303
Ivan | 125
sleigh | 125
Olya | 148
maxims | 236
Peter | 250
fedoras | 0
vlad | 0
oksana | 0
actually you need to make a mysql query
zeros down so ORDER BY case number when 0 then 2 else 1 end
did one of the options
order by case number when 0 then 2 else 1 end, substring(exp, 1, 2) asc
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question