CONVERT_TO
convert_toβ
descriptionβ
Syntaxβ
VARCHAR convert_to(VARCHAR column, VARCHAR character)
It is used in the order by clause. eg: order by convert(column using gbk), Now only support character can be converted to 'gbk'. Because when the order by column contains Chinese, it is not arranged in the order of Pinyin After the character encoding of column is converted to gbk, it can be arranged according to pinyin
exampleβ
mysql> select * from class_test order by class_name;
+----------+------------+-------------+
| class_id | class_name | student_ids |
+----------+------------+-------------+
| 6 | asd | [6] |
| 7 | qwe | [7] |
| 8 | z | [8] |
| 2 | ε | [2] |
| 3 | ε¦ | [3] |
| 1 | ε | [1] |
| 4 | εΌ | [4] |
| 5 | ζ | [5] |
+----------+------------+-------------+
mysql> select * from class_test order by convert(class_name using gbk);
+----------+------------+-------------+
| class_id | class_name | student_ids |
+----------+------------+-------------+
| 6 | asd | [6] |
| 7 | qwe | [7] |
| 8 | z | [8] |
| 1 | ε | [1] |
| 2 | ε | [2] |
| 3 | ε¦ | [3] |
| 5 | ζ | [5] |
| 4 | εΌ | [4] |
+----------+------------+-------------+
keywordsβ
convert_to