MySQL 'Order By' - sorting alphanumeric correctly

后端 未结 15 2136
执念已碎
执念已碎 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:40

    This works for type of data: Data1, Data2, Data3 ......,Data21. Means "Data" String is common in all rows.

    For ORDER BY ASC it will sort perfectly, For ORDER BY DESC not suitable.

    SELECT * FROM table_name ORDER BY LENGTH(column_name), column_name ASC;
    

提交回复
热议问题