convert_to

description

Syntax

VARCHAR convert_to(VARCHAR column, VARCHAR character)

在order by子句中使用,例如order by convert(column using gbk), 现在仅支持character转为’gbk’. 因为当order by column中包含中文时,其排列不是按照汉语拼音的顺序. 将column的字符编码转为gbk后,可实现按拼音的排列的效果.

exmaple

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]         |
+----------+------------+-------------+
作者:超级管理员  创建时间:2023-06-15 10:08
最后编辑:超级管理员  更新时间:2024-09-05 21:06