A simple example of MySQL sorting according to the pinyin of Chinese characters

  • 2021-07-01 08:25:35
  • OfStack

If the field for storing names uses GBK character set, it will be easy to handle, because GBK internal code itself adopts pinyin sorting method (3755 commonly used level 1 Chinese characters are sorted by pinyin, but not level 2 Chinese characters, but considering that names are commonly used Chinese characters, it is enough to sort them correctly only for level 1 Chinese characters).

Add order by name asc directly after the query statement; Query results are sorted in ascending order of last names;

If the field where the name is stored uses utf8 character set, the field needs to be transcoded when sorting; For the code is order by convert (name using gbk) asc; Similarly, the query results are sorted in ascending order of last names;


Related articles: