sql - MySQL natural sorting with text and numbers -


i have table item name, example:

... cheburashka detailed ear 10g. (o.box 5 pcs.) cheburashka detailed ear 12g. (o.box 5 pcs.) cheburashka detailed ear 4g. (o.box 5 pcs.) skittle 2 swivels 20g. (o.box 5 pcs.) skittle 2 swivels 6g. (o.box 5 pcs.) ... 

and need:

... cheburashka detailed ear 4g. (o.box 5 pcs.) cheburashka detailed ear 10g. (o.box 5 pcs.) cheburashka detailed ear 12g. (o.box 5 pcs.) skittle 2 swivels 6g. (o.box 5 pcs.) skittle 2 swivels 20g. (o.box 5 pcs.) ... 

etc, , need sort rows alphabetically, , value numbers - weight.

sql fiddle link - http://sqlfiddle.com/#!2/4cbd8/1

i tried sort rows length(), cast(), substring_index(), failed.

query 1:

select item_name items  order  reverse(mid( reverse(mid(replace(replace(replace(replace(replace(item_name,',',''),' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '),1,instr(replace(replace(replace(replace(item_name,' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '), 'g. (')-1)), instr(reverse(mid(replace(replace(replace(replace(replace(item_name,',',''),' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '),1,instr(replace(replace(replace(replace(item_name,' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '), 'g. (')-1)),' ') )), cast(reverse(mid( reverse(mid(replace(replace(replace(replace(replace(item_name,',',''),' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '),1,instr(replace(replace(replace(replace(item_name,' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '), 'g. (')-1)),1,   instr(reverse(mid(replace(replace(replace(replace(replace(item_name,',',''),' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '),1,instr(replace(replace(replace(replace(item_name,' . ','. '),'r. ','g. '),'d. ','g. '),' g ','g. '), 'g. (')-1)),' ') )) signed) 

results:

|                                                item_name | |----------------------------------------------------------| |   load cheburashka detailed ear 4g. ( o.box 5 pcs.) | |   load cheburashka detailed ear 6d. ( o.box 5 pcs.) | |   load cheburashka detailed ear 8g. ( o.box 5 pcs.) | |  load cheburashka detailed ear 10g. ( o.box 5 pcs.) | |  load cheburashka detailed ear 12g. ( o.box 5 pcs.) | | load cheburashka detailed ear 14g . ( o.box 5 pcs.) | | load cheburashka detailed ear 16g . ( o.box 5 pcs.) | | load cheburashka detailed ear 18g . ( o.box 5 pcs.) | | load cheburashka detailed ear 20g . ( o.box 5 pcs.) | | load cheburashka detailed ear 22g . ( o.box 3 pcs.) | | load cheburashka detailed ear 24g . ( o.box 3 pcs.) | | load cheburashka detailed ear 26g . ( o.box 3 pcs.) | | load cheburashka detailed ear 28g . ( o.box 3 pcs.) | | load cheburashka detailed ear 32g . ( o.box 3 pcs.) | | load cheburashka detailed ear 36g . ( o.box 3 pcs.) | | load cheburashka detailed ear 40g . ( o.box 3 pcs.) | |                  load cone dope 3d. ( o.box 5 pcs.) | |                  load cone dope 4g. ( o.box 5 pcs.) | |                  load cone dope 6d. ( o.box 5 pcs.) | |                 load cone dope, 8g. ( o.box 5 pcs.) | |                 load cone dope 10g. ( o.box 5 pcs.) | |                 load cone dope 12g. ( o.box 5 pcs.) | |                load cone dope 13g . ( o.box 5 pcs.) | |                load cone dope 15g . ( o.box 5 pcs.) | |                load cone dope 18g . ( o.box 5 pcs.) | |               load ovsinka dope 3d. ( o.box 5 pcs.) | |              load ovsinka dope, 7g. ( o.box 5 pcs.) | |              load ovsinka dope 10g. ( o.box 5 pcs.) | |             load ovsinka dope 14g . ( o.box 5 pcs.) | |             load ovsinka dope 18g . ( o.box 5 pcs.) | |               load skittle dope 6d. ( o.box 5 pcs.) | |              load skittle dope, 9g. ( o.box 5 pcs.) | |             load skittle dope 14g . ( o.box 5 pcs.) | |             load skittle dope 16g . ( o.box 5 pcs.) | |             load skittle dope 20g . ( o.box 5 pcs.) | |        load skittle 2 swivels 6d. ( o.box 5 pcs.) | |        load skittle 2 swivels 9g. ( o.box 5 pcs.) | |      load skittle 2 swivels 14g . ( o.box 5 pcs.) | |      load skittle 2 swivels 16g . ( o.box 5 pcs.) | |      load skittle 2 swivels 20g . ( o.box 5 pcs.) | |             oliva cargo dope, 3.5 g ( o.box 5 pcs.) | |               oliva cargo dope, 7g. ( o.box 5 pcs.) | |            oliva cargo dope, 10.5 g ( o.box 5 pcs.) | |              oliva cargo dope 14g . ( o.box 5 pcs.) | |                thumb load dope, 2r. ( o.box 5 pcs.) | |                 thumb load dope 3d. ( o.box 5 pcs.) | |                thumb load dope, 7g. ( o.box 5 pcs.) | |                thumb load dope 10g. ( o.box 5 pcs.) | 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -