zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

mysql 符串类型的数字排序(字符串转数字)[通俗易懂]

mysql排序 类型 通俗易懂 字符串 数字 符串
2023-06-13 09:11:47 时间

大家好,又见面了,我是你们的朋友全栈君。

针对字符串类型的字符排序 需要先转换成数字再进行排序

1.直接用加法

  字符串+0

select * from orders order by (mark+0) desc

2.使用函数

CAST(value as type); CONVERT(value, type);

注: 这里的type可以为: 浮点数 : DECIMAL 整数 : SIGNED 无符号整数 : UNSIGNED

select * from orders order by CONVERT(mark,SIGNED) desc

  select * from orders order by CAST(mark as SIGNED) desc

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/141712.html原文链接:https://javaforall.cn