order by 无法排序 mysql

这几天写项目的时候 要写一个排序 但是无论是正序还是倒序发现数据都没有变化。 后来仔细研究了下 order by 发现 order by只能对 int 或者date进行排序 当时我的数据类型是varchar 所以不能排序
现在说下解决方法

select * from table order by score asc; // 这个是正常的sql 排序语句  假设score是非int或者date类型的时候  是无法排序的。 
select * from table order by score+0 asc;// 这个是对非int date 类型。+0意思是转换成int类型  这地方需要注意的是假如你这个字段有特殊字符 那么 +0 是不会改变任何结果的

猜你喜欢

转载自blog.csdn.net/weixin_43944691/article/details/108384341