MySQL sorted by the first letter

If the content mysql field is all in English, so ordering direct conventional sort ASC DESC ASC DESC positive sequence flashback, we can.
If you want to row Chinese characters, in fact, it is pressing the alphabetical order
is usually when we query books, there will be sorted by name books, mostly due to the general database coding utf-8, his sort is alphabetical rule "a, b, c ..."
Here Insert Picture Description
From the above table to see if we will need to sort when sorting field into GBK encoding another sort, the sort can be achieved in accordance with the first letter of the name of the book, how to convert the encoding GBK is it? CONVERT function provided in MySQL (), this function can be used to obtain the value of a type

该函数的使用方式为 CONVERT(字段 USING GBK)

E.g:

SELECT * FROM table ORDER BY CONVERT(field USING GBK) ASC

If the table GBK encoding field use, we can directly order by value, because GBK itself is in accordance with pinyin alphabetical order ABCDEFGHIGK ..., the same time when the first would be more second, and so on.

If the table fields using UTF-8 encoding, then, we used to always coded, so that we can start to sort gbk converted using MySQL convert method.

SELECT * FROM TEST ORDER BY CONVERT(value USING GBK) ASC/DESC

Released seven original articles · won praise 11 · views 80000 +

Guess you like

Origin blog.csdn.net/dxyzhbb/article/details/104047547