簡體   English   中英

MySQL-排序規則(latin1_swedish_ci隱式)和(utf8_general_ci可強制執行操作'='的非法混合

[英]MySQL - illegal mix of collations (latin1_swedish_ci implicit) and (utf8_general_ci coercible for operation '='

當我執行以下查詢時,出現此錯誤:

錯誤代碼:1267。非法混合的排序規則(latin1_swedish_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE)用於操作'='

如果您需要此代碼的背景知識,請執行以下說明:
MySQL-如何自動執行將查詢數據從最近日期減去到前一天的日期查詢,並將日期戳記最新數據

我將“ 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  

從您的相關問題中可以猜到,您的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 

但最好更改表以具有正確的數據類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM