我可以在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)
解决方法:
问题是系统变量collation_connection设置为latin1_swedish_ci,其他所有内容均为utf8_general_ci.将collation_connection设置为utf8_general_ci可以使查询成功运行.