0

たとえば、アイテム名のテーブルがあります。

...
Cheburashka with detailed ear 10g. (O.Box 5 pcs.)
Cheburashka with detailed ear 12g. (O.Box 5 pcs.)
Cheburashka with detailed ear 4g. (O.Box 5 pcs.)
Skittle with two swivels 20g. (O.Box 5 pcs.)
Skittle with two swivels 6g. (O.Box 5 pcs.)
...

そして、私は必要です:

...
Cheburashka with detailed ear 4g. (O.Box 5 pcs.)
Cheburashka with detailed ear 10g. (O.Box 5 pcs.)
Cheburashka with detailed ear 12g. (O.Box 5 pcs.)
Skittle with two swivels 6g. (O.Box 5 pcs.)
Skittle with two swivels 20g. (O.Box 5 pcs.)
...

など、行をアルファベット順に並べ替える必要があり、値の数字 - 重み.

SQL Fiddle リンク - http://sqlfiddle.com/#!2/4cbd8/1

LENGTH()CAST()、で行を並べ替えようとしましSUBSTRING_INDEX()たが、すべて失敗しました。

4

2 に答える 2

0

まあ、これはちょっと醜いですが、あなたのsqlfiddleでうまくいくようです:

SELECT item_name

FROM items ORDER BY 
item_name,
cast(substring(item_name,LEAST(
    if (Locate('0',item_name) >0,Locate('0',item_name),999),
    if (Locate('1',item_name) >0,Locate('1',item_name),999),
    if (Locate('2',item_name) >0,Locate('2',item_name),999),
    if (Locate('3',item_name) >0,Locate('3',item_name),999),
    if (Locate('4',item_name) >0,Locate('4',item_name),999),
    if (Locate('5',item_name) >0,Locate('5',item_name),999),
    if (Locate('6',item_name) >0,Locate('6',item_name),999),
    if (Locate('7',item_name) >0,Locate('7',item_name),999),
    if (Locate('8',item_name) >0,Locate('8',item_name),999),
    if (Locate('9',item_name) >0,Locate('9',item_name),999)
  )) as unsigned)
于 2013-10-07T13:13:12.433 に答える