[英]MySQL - illegal mix of collations (latin1_swedish_ci implicit) and (utf8_general_ci coercible for operation '='
When I execute the query below i get this error: 当我执行以下查询时,出现此错误:
Error Code: 1267. Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' 错误代码:1267。非法混合的排序规则(latin1_swedish_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE)用于操作'='
If you need background behind this code, here is the explanation: 如果您需要此代码的背景知识,请执行以下说明:
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 MySQL-如何自动执行将查询数据从最近日期减去到前一天的日期查询,并将日期戳记最新数据
I set the 'facebook_insight' table collation to: 'utf8_general_ci,' but I still get the error. 我将“ facebook_insight”表排序规则设置为:“ utf8_general_ci”,但仍然收到错误。 Can anyone help me? 谁能帮我?
MySQL Query: 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
As I can guess from your related question , the type of your timestamp
column is not any of date, datetime or timestamp
. 从您的相关问题中可以猜到,您的timestamp
列的类型不是date, datetime or timestamp
。 It's probably varchar
or text
. 可能是varchar
或text
。
So when you try to add INTERVAL 1 DAY
to the value which is not time type you get the error. 因此,当您尝试将INTERVAL 1 DAY
添加到不是时间类型的值时,会出现错误。
You have to convert your timestamp
column to any of date, datetime or timestamp
data types. 您必须将您的timestamp
列转换为任何date, datetime or timestamp
数据类型。
As a quick fix you can use STR_TO_DATE()
function in your query: 作为快速解决方案,您可以在查询中使用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
But better alter your table in order to have correct datatypes. 但最好更改表以具有正确的数据类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.