2

我可以在 MySQL 中运行这个查询,它工作得很好。但是,我需要对 ctd.FULL_DESCIPTION (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)
4

1 回答 1

4

问题是系统变量 collat​​ion_connection 被设置为 latin1_swedish_ci,其他的都是 utf8_general_ci。将 collat​​ion_connection 设置为 utf8_general_ci 允许查询成功运行。

于 2012-10-04T13:56:18.740 回答