先看sql
o.city_name AS '城市', o.city_code AS '城市编码', o.comp_name AS '公司', o.comp_code AS '分公司编码', b.brand_name AS '品牌', a.account_code AS '被处罚系统号', l.occur_time AS '处罚发生日期', l.penalize_time AS '处罚最终判罚日期', l.create_time AS '处罚数据导入时间', l.violation_behavior AS '违规行为名称', l.reason AS '事件描述', l.ryb_category AS '红黄线', l.add_score AS '分值', l.credit_score_log_type AS '类别' FROM credit.credit_account a RIGHT JOIN credit.credit_score_log l ON l.credit_account_id = a.id LEFT JOIN credit.org o ON o.comp_code = l.comp_code LEFT JOIN credit.brand_comp b ON b.comp_code = o.comp_code.user_credit_score_log u ON u.user_code = a.account_code;
报错提示:[HY000][1267] Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='
怀疑是 字符集 或者 排序规则 对应不上,于是通过mysql指令排查下字符集
SHOW FULL COLUMNS FROM credit.credit_account; SHOW FULL COLUMNS FROM credit.org; SHOW FULL COLUMNS FROM credit.credit_score_log; SHOW FULL COLUMNS FROM credit.brand_comp;
credit_account表,org表,credit_score_log表,brand_comp表 四张表字符集分别如下:
经过分析发现 最后一张表 brand_comp 的varchar字段Collation 是 utf8mb4_unicode_ci,前三张表varchar字段段Collation 都是 utf8mb4_general_ci
于是更改表的字符集和排序规则,命令如下
ALTER TABLE brand_comp CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
此时再查询最后一张表
排序规则更改后,再执行sql,完美运行,问题解决!