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?
谢谢.
推荐答案
试试这个:
ORDER BY CAST(thecolumn AS int)
这篇关于SQL ORDER 字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文