MySQL 'Order By' - sorting alphanumeric correctly

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

    SELECT length(actual_project_name),actual_project_name,
    SUBSTRING_INDEX(actual_project_name,'-',1) as aaaaaa,
    SUBSTRING_INDEX(actual_project_name, '-', -1) as actual_project_number,
    concat(SUBSTRING_INDEX(actual_project_name,'-',1),SUBSTRING_INDEX(actual_project_name, '-', -1)) as a
    FROM ctts.test22 
    order by 
    SUBSTRING_INDEX(actual_project_name,'-',1) asc,cast(SUBSTRING_INDEX(actual_project_name, '-', -1) as unsigned) asc
    

提交回复
热议问题