Chinese characters (Chinese) in mysql sorted in the first letters of the pinyin

Because the encoding format of the table can be set in the database, there are differences in the sorting of Chinese under different encoding formats. The following are the sorting methods under common encodings.

1. If the character encoding of a field in the data table is utf8_general_ci, the sorting method:

ORDER BY  CONVERT (table alias. Field name USING gbk) COLLATE gbk_chinese_ci ASC; 

Example

SELECT * FROM mg_clinic mc ORDER BY CONVERT(mc.`CLNAME `USING gbk) COLLATE gbk_chinese_ci ASC;

share picture

2, if the data table The character encoding of a field is latin1_swedish_ci, and the sorting method is:

order by birary (table alias. field name) asc ;

< strong>3. If the character code of a field in the data table is GBK, the sorting method:

Direct sorting is fine, because the GBK code is originally sorted by the first letter of Chinese characters.

order by table Alias. Field name asc;

Reference:

https://blog.csdn.net/ mawming/article/details/52045771

https://my.oschina.net/u/999578/blog/150392

https://blog.csdn.net/stephenxu111/ article/details/4436181

https://blog.csdn.net/w410589502/article/details/58049091

The original link:

https://www.cnblogs.com/poterliu/p/11596334.html

ORDER BY CONVERT(table alias. Field name USING gbk) COLLATE gbk_chinese_ci ASC;

SELECT * FROM mg_clinic mc ORDER BY CONVERT(mc.`CLNAME` USING gbk) COLLATE gbk_chinese_ci ASC;

order  by birary (table alias. field name) asc ;

order by table alias. Field name asc;

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2938 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.