MySQL 'Order By' - sorting alphanumeric correctly

后端 未结 15 2319
执念已碎
执念已碎 2020-11-22 12:02

I want to sort the following data items in the order they are presented below (numbers 1-12):

1
2
3
4
5
6
7
8
9
10
11
12

However, my query - using

15条回答
  •  旧巷少年郎
    2020-11-22 12:47

    I hate this, but this will work

    order by lpad(name, 10, 0)  <-- assuming maximum string length is 10
                                <-- you can adjust to a bigger length if you want to
    

提交回复
热议问题