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;
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;