MySQL order by string with numbers

后端 未结 7 870
谎友^
谎友^ 2020-12-11 01:57

I have strings such as M1 M3 M4 M14 M30 M40 etc (really any int 2-3 digits after a letter) When I do \" ORDER BY name \" this returns:

M1, M14, M3

7条回答
  •  春和景丽
    2020-12-11 02:13

    Try remove the character with SUBSTR. Then use ABS to get the absolute value from field:

    SELECT * FROM table ORDER BY ABS(SUBSTR(field,1));
    

提交回复
热议问题