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 后,可实现按拼音的排列的效果。

example

  1. mysql> select * from class_test order by class_name;
  2. +----------+------------+-------------+
  3. | class_id | class_name | student_ids |
  4. +----------+------------+-------------+
  5. | 6 | asd | [6] |
  6. | 7 | qwe | [7] |
  7. | 8 | z | [8] |
  8. | 2 | | [2] |
  9. | 3 | | [3] |
  10. | 1 | | [1] |
  11. | 4 | | [4] |
  12. | 5 | | [5] |
  13. +----------+------------+-------------+
  14. mysql> select * from class_test order by convert(class_name using gbk);
  15. +----------+------------+-------------+
  16. | class_id | class_name | student_ids |
  17. +----------+------------+-------------+
  18. | 6 | asd | [6] |
  19. | 7 | qwe | [7] |
  20. | 8 | z | [8] |
  21. | 1 | | [1] |
  22. | 2 | | [2] |
  23. | 3 | | [3] |
  24. | 5 | | [5] |
  25. | 4 | | [4] |
  26. +----------+------------+-------------+

keywords

  1. convert_to