Someone asked, for example, if the data table contains sortid characters ranging from A1 to A29. If "order by sortid" is added to the query, the sorting will be A1, A10, a11... a19, A2 ,.. a29, A3, a4... a9
How can we make it output in the order of A1, A2, a3... A28, A29?
Create a test table
Create Table 'test _ njj '(
'Id' int (10) Not null auto_increment,
'Sortid' varchar (20) not null,
'User _ id' int (10) Not null default '0 ',
Primary Key ('id ')
) Engine = InnoDB default charset = utf8;
We only need to use MySQL built-in functionsSubstring (STR, POS)
Split sortid.
SelectSubstring (sorid, 2) from test_njj
We can see that a has been filtered out, but the sorting is still incorrect, because although the split number is a number, it is still considered as a string, so it is necessary to convert it into a number to make
Substring (sorid, 2) * 1
Therefore
Select * From test_njj order by substring (sortid, 2) * 1;
You can.
The above test passed in mysql4.1.18