问题
How to Sort Character column numerically. I have a column of numbers stored as chars. When I do a ORDER BY for this column I get the following:
100D
131A
200
21B
30
31000A
etc.
There may be chance of having one Alphabet at the end. How can I order these chars numerically? Do I need to convert something or is there already an SQL command or function for this?
回答1:
You could use something like:
ORDER BY Cast(regexp_replace(yourcolumn, '[^0-9]', '', 'g') as integer)
来源:https://stackoverflow.com/questions/8587640/order-by-char-column-numerically