解决数字字符串排序问题(解决10和2的排序前后问题)

字符串转换数字的方法:(type: DECIMAL 浮点数,SIGNED 整数,UNSIGNED 无符号整数)
  CAST(value as type)
  CONVERT(value, type)
select * from table order by cast(value as signed);
select * from table order by convert(value, signed);
select * from table order by value * 1;
select * from table order by value + 0;

解决中文排序和查找的时候,对汉字的排序和查找结果往往都是错误的问题。

  • MySQL在查询字符串时是大小写不敏感的,在编绎MySQL时一般以ISO-8859字符集作为默认的字符集,因此在比较过程中中文编码字符大小写转换造成了这种现象。
方法一:
对于包含中文的字段加上”binary”属性,使之作为二进制比较,例如将”name char(10)”改成”name char(10)binary”。
方法二:
select * from mytable order by CONVERT(chineseColumnName USING gbk);