按字符列按数字顺序排序 [英] Order by char column numerically
本文介绍了按字符列按数字顺序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何对字符列进行数字排序. 我有一列数字存储为字符.当我对此列执行ORDER BY时,我得到以下信息:
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.
最后可能会有一个字母. 如何按数字顺序订购这些字符?我是否需要转换某些东西,或者已经有用于此的SQL命令或函数?
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?
推荐答案
您可以使用类似的东西:
You could use something like:
ORDER BY Cast(regexp_replace(yourcolumn, '[^0-9]', '', 'g') as integer)
这篇关于按字符列按数字顺序排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文