Home  >  Article  >  Database  >  MySQL字段按照拼音排序

MySQL字段按照拼音排序

WBOY
WBOYOriginal
2016-06-07 17:12:50889browse

我们的MySQL使用latin1的默认字符集,也就是说,对汉字字段直接使用GBK内码的编码进行存储,当需要对一些有汉字的字段进行拼音排

我们的MySQL使用latin1的默认字符集,,也就是说,对汉字字段直接使用GBK内码的编码进行存储,当需要对一些有汉字的字段进行拼音排序时(特别涉及到类似于名字这样的字段时),默认无法通过order by关键字正确排序。

经过网上查找,网上的办法大多是针对使用utf8字符集的数据库,主要的方法有:

1)直接转换字段为gbk,比如:

SELECT * FROM table ORDER BY CONVERT( chinese_field USING gbk ) ;

或者干脆将相应字段改为gbk字符集。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn