mysql in solving scheduling problems 1.1,1.1.1,10.1 No.

Database has sort field (varchar type) reads:

1

1.1

2

2.1

2.1.1

10.1

 

I think the solution is to separate the merge field:

Such as

1.1 merged into partition 001001

2 combined into partition 002

10.1 divider, said the merger 010001

You can then sorted in ascending order.

 

Functions implemented attached

create definer=`root`@`localhost` function `split_pad`(str varchar (1000),delimiter varchar(1)) returns varchar(200)
begin
    declare cur_str varchar(200);
    declare sub_len int;
    declare sub_str varchar(200);
    declare ret_str varchar(200);
    declare loop_count int;
   
    set cur_str = str;
    set sub_len = -1;
    set ret_str = '';
    set loop_count = 0;
   
    repeat
        set cur_str = substring(cur_str,sub_len + 2);
        set sub_str = substring_index(cur_str,delimiter,1);
        set sub_len = length(sub_str);
       
        if sub_len !=0 then
           set ret_str = concat(ret_str,lpad(sub_str,3,'0'));
        end if;
       
        set loop_count = loop_count + 1;
    until sub_len = 0
    end repeat;
   
    return ret_str;
end;

 

Published 38 original articles · won praise 4 · Views 190,000 +

Guess you like

Origin blog.csdn.net/tomatozq/article/details/8670251