我正在尝试加入一些表,但是我的加入语句失败.我相信这是因为第二个联接中的列名称是“名称”,也许MySQL认为我正在尝试访问属性?我该如何解决?
SELECT surgery_city.*, s.surgeon_type, st.abbrev
FROM surgery_city
LEFT JOIN surgery_key as s ON s.surg_id = treatment_id
LEFT JOIN states as st ON st.name = surgery_city.state
WHERE treatment_id='10001'
问题是我引用st.name的第二个左联接-关于如何正确引用该列的任何想法?不幸的是,此时不能更改表中的列名:( ..
谢谢,
银虎
更新:
我在上面的查询中得到的错误是:
[Err] 1267-操作’=’的归类(utf8_unicode_ci,IMPLICIT)和(utf8_general_ci,IMPLICIT)的非法混合
当我用反勾号包围该字段时,我得到以下信息:
LEFT JOIN states as st ON `st.name` = seo_surgery_city.state
我得到以下内容:
[Err] 1054-‘on子句’中的未知列’st.name’
它也失败
LEFT JOIN states as st ON st.`name` = seo_surgery_city.state
(单引号=此处有反勾,但此处无法正确显示)
[Err] 1267-操作’=’的归类(utf8_unicode_ci,IMPLICIT)和(utf8_general_ci,IMPLICIT)的非法混合
也失败
LEFT JOIN states as st ON `st`.`name` = seo_surgery_city.state
[Err] 1267-操作’=’的归类(utf8_unicode_ci,IMPLICIT)和(utf8_general_ci,IMPLICIT)的非法混合
解决方法:
您应该在列名中加上反引号:
st.`name`
UPD
问题是列具有不同的排序规则,请尝试以下操作:
SELECT surgery_city.*, s.surgeon_type, st.abbrev
FROM surgery_city
LEFT JOIN surgery_key as s ON s.surg_id = treatment_id
LEFT JOIN states as st ON st.name = (surgery_city.state COLLATE utf8_unicode_ci)
WHERE treatment_id='10001'
但是要解决此问题,您应该更新以下列之一的排序规则:states.name或seo_surgery_city.state.它们都应具有utf8_general_ci.
标签:mysql-error-1267,mysql
来源: https://codeday.me/bug/20191201/2083959.html