开发者

Mysql how to ORDER BY?

I need to order following rows:

10a

10b

11c

5a

5b

5c

9c

and the result should be:

5a

5b

5c

9c

10a

10b

11c

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜