sql - Convert text into number in MySQL query -
is possible convert text number within mysql query? have column identifier consists name , number in format of "name-number". column has varchar type. want sort rows according number (rows same name) column sorted according character order, i.e.
name-1 name-11 name-12 name-2
if cut of number, can convert 'varchar' number 'real' number , use sort rows? obtained following order.
name-1 name-2 name-11 name-12
i cannot represent number separate column.
edited 2011-05-11 9:32
i have found following solution ... order column * 1
. if name not contain numbers save use solution?
this should work:
select field,convert(substring_index(field,'-',-1),unsigned integer) num table order num;
Comments
Post a Comment