Order by char column numerically

半世苍凉 提交于 2019-12-12 10:16:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!