sql order by - MySQL sorting string values with numbers? -
my data this:
krypton-4xlv krypton-3xstg krypton-16xth krypton-8xth krypton-8xlv
when call order by
on column values sorted this:
krypton-16xth krypton-3xstg krypton-4xlv krypton-8xlv krypton-8xth
is there way sort like?
krypton-4xlv krypton-8xlv krypton-3xstg krypton-8xth krypton-16xth
here sql fiddle: http://sqlfiddle.com/#!9/6d061/2
try following:
select code (select *, substring(code, locate('-', code) + 1, length(code)) o products )t order substring(o, locate('x', o), length(code)), cast(o unsigned)
Comments
Post a Comment