开发者

Mysql how to ORDER BY?

开发者 https://www.devze.com 2023-04-01 07:19 出处:网络
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:

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

精彩评论

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