mysql将字符串转成数字
浏览量:417
以字符串类型的数字进行排序,sql语句怎么写?
how:
需要先转换成数字再进行排序
1.直接用加法
字符串+0
eg:
from orders order by (mark+0) desc
2.使用函数
CAST(value as type);
ConVERT(value, type);
注:
这里的type可以为:
浮点数 : DECIMAL
整数 : SIGNED
无符号整数 : UNSIGNED
eg:
from orders order by ConVERT(mark,SIGNED) desc
from orders order by CAST(mark as SIGNED) desc


感谢支持与鼓励~