我可以在MySQL中运行此查询,它运行正常。但是,我需要对ctd.FULL_DESCRIPTION(TEXT数据类型)执行LEFT功能,并且只需要前3600个字符,当我尝试这样做时(使用LEFT(ctd.FULL_DESCIPTION,3600))我得到错误:非法混合操作'UNION'的整理(utf8_general_ci,IMPLICIT)和(latin1_swedish_ci,COERCIBLE)
我在此错误中找到的所有内容都表明我的其中一列未与其他列进行整理。我在此查询中的所有表上都显示了一个SHOW FULL COLUMNS,并且整理的所有内容都使用utf8_general_ci。数据库的默认排序规则也是utf8。我找不到latin1_swedish_ci在哪里。我错过了什么?
SELECT
CONCAT(''73'',RIGHT(CONCAT(''000000'',cd.CHANGEID),6)) AS CHANGEID,
LEFT(cd.TITLE,80) AS CHANGETITLE, FROM_UNIXTIME(cd.CREATEDTIME/1000) AS PRJDATE,
LEFT(sd.NAME,10) AS STATUSNAME, wo.WORKORDERID AS WOID, LEFT(wo.TITLE,80) AS WOTITLE,
LEFT(au.FIRST_NAME,10) as TECHNAME, ctd.FULL_DESCRIPTION AS CHANGEDSC
FROM servicedesk.changedetails cd, servicedesk.incidenttochangemapping itcm,
servicedesk.workorder wo, servicedesk.stagedefinition sd, servicedesk.workorderstates
wos, servicedesk.sduser sdu, servicedesk.aaauser au, servicedesk.changetodescription ctd
WHERE cd.CHANGEID = itcm.CHANGEID and itcm.WORKORDERID = wo.WORKORDERID and
cd.STAGEID = sd.STAGEID and wo.WORKORDERID = wos.WORKORDERID and wos.OWNERID =
sdu.USERID and sdu.USERID = au.USER_ID and cd.CHANGEID = ctd.CHANGEID and
cd.STAGEID NOT IN (3,2) and cd.CATEGORYID IN
(301,2701,3601,3602,3605,3606,4201,4202,4501,4502,4801) and wos.REQUESTTYPEID IN
(301,601)
UNION
SELECT CONCAT(''73'',RIGHT(CONCAT(''000000'',cd.CHANGEID),6)) AS CHANGEID,
LEFT(cd.TITLE,80) AS CHANGETITLE, FROM_UNIXTIME(cd.CREATEDTIME/1000) AS PRJDATE,
LEFT(sd.NAME,10) AS STATUSNAME, '''' AS WOID, '''' AS WOTITLE, '''' AS TECHNAME,
ctd.FULL_DESCRIPTION AS CHANGEDSC
FROM servicedesk.changedetails cd, servicedesk.stagedefinition sd,
servicedesk.changetodescription ctd
WHERE cd.STAGEID = sd.STAGEID and cd.CHANGEID = ctd.CHANGEID and cd.STAGEID NOT
IN (3,2) and cd.CATEGORYID IN
(301,2701,3601,3602,3605,3606,4201,4202,4501,4502,4801) and NOT EXISTS (
SELECT NULL FROM servicedesk.incidenttochangemapping itcm WHERE cd.CHANGEID =
itcm.CHANGEID)
答案 0 :(得分:4)
问题是系统变量collation_connection设置为latin1_swedish_ci,其他一切都是utf8_general_ci。将collation_connection设置为utf8_general_ci可以使查询成功运行。