Diese Abfrage wird die Zeichenfolge in Teile aufgeteilt:
select t.col
, cast(num1 as unsigned) n1
, cast(num2 as unsigned) n2
, cast(num3 as unsigned) n3
, cast(num4 as unsigned) n4
, cast(num5 as unsigned) n5
, cast(num6 as unsigned) n6
from (
select t.col
, SUBSTRING_INDEX(t.col, '-', 1) str
, SUBSTRING_INDEX(t.col, '-', -3) num1
, SUBSTRING_INDEX(t.col, '.', -3) num2
, SUBSTRING_INDEX(t.col, '-', -2) num3
, SUBSTRING_INDEX(t.col, '.', -2) num4
, SUBSTRING_INDEX(t.col, '-', -1) num5
, SUBSTRING_INDEX(t.col, '.', -1) num6
from Table1 t
) t;
--
| col | n1 | n2 | n3 | n4 | n5 | n6 |
|------------------|----|----|----|----|----|----|
| XYZ-1.0-7.0-1 | 1 | 0 | 7 | 0 | 1 | 0 |
| XYZ-1.0-27.0-5.7 | 1 | 0 | 27 | 0 | 5 | 7 |
| XYZ-1.0-20.0-4.6 | 1 | 0 | 20 | 0 | 4 | 6 |
| XYZ-1.0-10.0-2.4 | 1 | 0 | 10 | 0 | 2 | 4 |
http://sqlfiddle.com/#!9/d3770/1
Verwenden Sie die Teile sortieren Ihr Ergebnis fo:
select t.col
from (
select t.col
, SUBSTRING_INDEX(t.col, '-', 1) str
, SUBSTRING_INDEX(t.col, '-', -3) num1
, SUBSTRING_INDEX(t.col, '.', -3) num2
, SUBSTRING_INDEX(t.col, '-', -2) num3
, SUBSTRING_INDEX(t.col, '.', -2) num4
, SUBSTRING_INDEX(t.col, '-', -1) num5
, SUBSTRING_INDEX(t.col, '.', -1) num6
from Table1 t
) t
order by str
, cast(num1 as unsigned)
, cast(num2 as unsigned)
, cast(num3 as unsigned)
, cast(num4 as unsigned)
, cast(num5 as unsigned)
, cast(num6 as unsigned)
http://sqlfiddle.com/#!9/d3770/2
Sie c ein beseitigen auch die Unterabfrage:
select t.col
from Table1 t
order by SUBSTRING_INDEX(t.col, '-', 1)
, cast(SUBSTRING_INDEX(t.col, '-', -3) as unsigned)
, cast(SUBSTRING_INDEX(t.col, '.', -3) as unsigned)
, cast(SUBSTRING_INDEX(t.col, '-', -2) as unsigned)
, cast(SUBSTRING_INDEX(t.col, '.', -2) as unsigned)
, cast(SUBSTRING_INDEX(t.col, '-', -1) as unsigned)
, cast(SUBSTRING_INDEX(t.col, '.', -1) as unsigned)
http://sqlfiddle.com/#!9/d3770/5
Was zuerst * 1.11 * oder * 1.2 * kommt? –
Bestellung wird 1.0 dann 1.1 und so weiter. Und es wird in allen Fällen nach "-" Zeichen verwendet. – steven