1.问题描述:

在进行两个数据表联合查询时,由于数据库编码不一致,导致查询的时候报错

1267 - Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and
(utf8mb4_general_ci,IMPLICIT) for operation ‘=’

2.问题解决

需要增加关联字段的转换即可

  • 语法
  • convert(‘column’ using’ utf8)

SELECT
dc.id,dc.data_id,dc.data_ruid,dc.course_ruid,
c.name as course_name,
(select department_ruid from department_course dc where dc.course_id= c.id ) as department_ruid,
(SELECT name FROM ua_sysinfo.department WHERE RUID = CONVERT(department_ruid using utf8) ) as department_name
FROM
data_course dc ,course c where dc.course_ruid=c.ruid and dc.data_id = 379277

3.扩展

mysql 排序方法 “order by” 排序规则

编码 排序规则
utf-8mb4 按英文字母a,b,c规则排序
gbk 按汉字拼音首字母排序
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐