开发者

How do you sort fields which have numbers in a mathematical order

The following users are present in our database..

create table users (id, name);

name [u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, ...]

If the above field is sorted in an ascending fashion, the output is as follows..

u1, u10, u11, u2, u开发者_如何学Go3, u4 ...

Is it possible to sort this in the order at the top (i.e. list all single digits, double digits ...)


Try:

SELECT *
FROM users
ORDER BY CAST(SUBSTR(name FROM 2) AS UNSIGNED)


You could try this:

SELECT name
FROM users
ORDER BY LENGTH(name), name
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜