Mysql how to ORDER BY?
I need to order following rows:
10a 10b 11c 5a 5b 5c 9cand the result should be:
5a 5b 5c 9c 10a 10b 11cnow my query looks like this:
SELECT klass,id FROM klassid WHERE klass!='' ORDER B开发者_运维知识库Y klass ASC
Is it possible?
thanks in advance
To ensure numerical ordering, coerce the value to an integer. An easy way to do this is to put it in a numeric expression context.
Then to resolve ties, order by the original string value.
SELECT klass,id FROM klassid WHERE klass!=''
ORDER BY klass+0 ASC, klass ASC
精彩评论