sql order by - Need a help for sort in mysql -


hi want sort table .the field contains numbers,alphabets , numbers alphabets ie,

 1 2 1a 11a 6a b 

i want sort to,

 1 1a 2 6a 11a b

my code is,

select * t order cast(st signed), st 
result is,

 b 1 1a 2 6a 11a 

i found code in url

"http://www.mpopp.net/2006/06/sorting-of-numeric-values-mixed-with-alphanumeric-values/"
please me

this required sort order, in presence of 0 in table;

select * t  order    st regexp '^[[:alpha:]].*',    st+0,    st 

an sqlfiddle test with.

  • as first sort criteria, sorts anything starts letter after doesn't. that's regexp does.
  • as second sort criteria sorts numerical value string starts (st+0 adds 0 numerical part string starts , returns int)
  • as last resort, sorts string alphabetical ones in order.

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -