【问题标题】:MySQL - illegal mix of collations (latin1_swedish_ci implicit) and (utf8_general_ci coercible for operation '='MySQL - 排序规则(latin1_swedish_ci 隐式)和(utf8_general_ci coercible for operation '=' 的非法组合
【发布时间】:2017-07-06 18:42:43
【问题描述】:

当我执行下面的查询时,我得到了这个错误:

错误代码:1267。非法混合排序规则 (latin1_swedish_ci,IMPLICIT) 和 (utf8_general_ci,COERCIBLE) 用于操作 '='

如果您需要此代码背后的背景,这里是解释:
MySQL - How Can I Automate a View Query That Subtracts Metrics From the Most Recent Date To The Previous Day & Date Stamps The Most Recent Data

我将“facebook_insight”表排序规则设置为:“utf8_general_ci”,但仍然出现错误。谁能帮帮我?

MySQL 查询:

CREATE VIEW `facebook_insights` AS  
SELECT  
  t1.id  
, t1.timestamp  
, t1.message  
, t1.posted  
, t1.permalink_url  
, t1.caption  
, t1.link  
, t1.type  
, t1.post_impressions - t2.post_impressions as Impressions  
, t1.post_impressions_organic - t2.post_impressions_organic as Post_Impressions_Organic  
, t1.post_impressions_paid - t2.post_impressions_paid as Post_Impressions_Paid  
, t1.post_engaged_users - t2.post_engaged_users as Post_Engaged_Users  
, t1.post_consumptions - t2.post_consumptions as Post_Consumptions  
, t1.post_negative_feedback - t2.post_negative_feedback as 
Post_Negative_Feedback  
, t1.post_negative_feedback_unique - t2.Post_Negative_Feedback_Unique as 
Post_Negative_Feedback_Unique  
, t1.post_impressions_fan - t2.post_impressions_fan as Post_Impressions_Fan  
, t1.post_impressions_fan_paid - t2.post_impressions_fan_paid as 
Post_Impressions_Fan_Paid  
, t1.post_engaged_fan - t2.Post_Engaged_Fan as Post_Engaged_Fan  
, t1.post_video_complete_views_organic - 
t2.post_video_complete_views_organic as Post_Video_Complete_Views_Organic  
, t1.post_video_complete_views_paid - t2.post_video_complete_views_paid as 
Post_Video_Complete_Views_Paid  
, t1.post_video_views_10s - t2.post_video_views_10s as Post_Video_Views_10s  
, t1.post_video_views_10s_unique - t2.post_video_views_10s_unique as 
Post_Video_Views_10s_Unique  
, t1.post_video_views_organic - t2.post_video_views_organic as 
Post_Video_Views_Organic  
, t1.post_video_views_paid - t2.post_video_views_paid as 
Post_Video_Views_Paid  
, t1.post_video_views_clicked_to_play - t2.post_video_views_clicked_to_play 
as Post_Video_Views_Clicked_to_Play  

FROM  
unpaid_media.facebook_insight t1  
JOIN unpaid_media.facebook_insight t2  
ON t1.id = t2.id   
and t1.timestamp  = t2.timestamp + INTERVAL 1 DAY  

【问题讨论】:

  • 排序规则问题不在于表格。它是 INTERVAL 1 DAY,您可能需要更改它的排序规则。您的数据库的默认排序规则是什么?
  • @SloanThrasher ,我的数据库的默认排序规则是“latin1 - 默认排序规则”。

标签: mysql mysql-workbench mysql-error-1267


【解决方案1】:

我可以从您的related question 中猜到,您的timestamp 列的类型不是date, datetime or timestamp 中的任何一个。可能是varchartext

因此,当您尝试将 INTERVAL 1 DAY 添加到不是时间类型的值时,您会收到错误。

您必须将您的 timestamp 列转换为任何 date, datetime or timestamp 数据类型。

作为一种快速修复,您可以在查询中使用STR_TO_DATE() 函数:

CREATE VIEW `facebook_insights` AS
...
and STR_TO_DATE(t1.timestamp,'%m/%d/%Y') = STR_TO_DATE(t2.timestamp,'%m/%d/%Y') + INTERVAL 1 DAY 

但最好更改您的表以获得正确的数据类型。

【讨论】:

  • 谢谢!就是这样,我的“时间戳”列是一个文本值。 -尤利斯
猜你喜欢
  • 2010-09-16
  • 2010-10-30
  • 2015-06-03
  • 2011-08-29
  • 2015-09-16
  • 2010-10-21
  • 1970-01-01
  • 2014-12-04
  • 2011-06-13
相关资源
最近更新 更多