SQL ORDER数字字符 [英] SQL ORDER chars numerically
本文介绍了SQL ORDER数字字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一列数字存储为字符。当我对此列执行ORDER BY时,会得到以下结果:
I have a column of numbers stored as chars. When I do a ORDER BY for this column I get the following:
100
131
200
21
30
31000
等。
100
131
200
21
30
31000
etc.
如何订购这些字符数字?我需要转换的东西或已经有一个SQL命令或函数为此?
How can I order these chars numerically? Do I need to convert something or is there already an SQL command or function for this?
谢谢。
推荐答案
Try this:
ORDER BY CAST(thecolumn AS int)
这篇关于SQL ORDER数字字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文