MySQL string sorting

topic description

the database has a list of name data as follows
* * Biography of Chuqiao Episode 1
Biography of Chuqiao Episode 2
.
Biography of Chuqiao Episode 10 * *

or
Biography of Chuqiao 02
Biography of Chuqiao 02
.
Biography of Chuqiao 11

how to sort by size habit

sources of topics and their own ideas

what I do now is customize a function get_num_from_char to extract consecutive numbers
and then order by get_num_from_char (name)
do my predecessors have any better solutions

related codes

originally intended to use a separate field such as sort to manage this sort
, but the user imported the list from a library and did not want to deal with it manually

Mar.23,2022

as you said, write a Filter function get_num_from_char (name) to return a sequence number, and then save it to a field
for example, a very simple idea is to replace one, two, three with 123 , and then leave the number 0-9 .

XXX episode 1 to 1
XXXX-002 episode-HD to 002
season 1 episode 003 , to 1003
season 2 episode 004 , to 2004
season 3 episode 005 .1080P < / code

Save the results to a rank field, and then use this field for order by sorting
as long as you keep the same series of names in a similar format

.

complain, sort is a verb, database field, please use noun
in addition, you have seen that direct string sorting. It can only be said that imagination is beautiful.
actually becomes 1, 10, 11. 2, 20, 21. 3, 30, 31. this


order by get_num_from_char (name) is not recommended because it will degenerate the index on name into a full index scan.
it is actually better to use a single field to deal with it.


originally thought that the default sorting could also be used, but ignored some cases, thanks to @ month Lord LM's reminder

it is better to add a new field. When inserting data, the value of this field is automatically set to the number of sets (automatically processed by the program), which is transparent to the user. It is very convenient to add fields either automatically sort or manually adjust the order later


it is recommended to add fields. While inserting data, the code processes the number of sets and inserts them into the corresponding fields

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e506ad-656c8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e506ad-656c8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?