Home  >  Article  >  Database  >  Detailed explanation and examples of MySQL sorting Chinese

Detailed explanation and examples of MySQL sorting Chinese

巴扎黑
巴扎黑Original
2017-05-14 14:17:171271browse

This article mainly introduces the detailed explanation and examples of MySQL's sorting of Chinese. Friends in need can refer to the following

MySQL's detailed explanation of sorting Chinese

MySQL only supports sorting date, time and English strings by default. If you order by for Chinese, you may not get the desired results. For example, the following query will not sort according to the pinyin of Chinese characters as we think. :


SELECT * from user order by user_name;

If you want to sort relative to Chinese, you can use CONVERT (coloum_name USING GBK) to convert Chinese to GBK encoding, and then sort, you can achieve the sorting based on Hanzi Sort by pinyin:


SELECT * from user order by CONVERT(user_name USING GBK);

The above is the detailed content of Detailed explanation and examples of MySQL sorting Chinese. For more information, please follow other related articles on the PHP Chinese website!

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