2017-07-06 37 views
0

utf8_general_ci強制轉換當我執行下面的查詢我收到此錯誤:MySQL的 - 歸類(latin1_swedish_ci隱含的)和非法混合(操作「=」

錯誤代碼:1267排序規則的非法組合(latin1_swedish_ci隱式)和(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' 表collat離子:'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 
+1

排序問題與該表不匹配。它與INTERVAL 1天,你可能不得不改變它的整理。你的數據庫的默認排序規則是什麼? –

+0

@SloanThrasher,我的數據庫的默認排序規則是'latin1 - 默認排序規則'。 –

回答

2

,我可以從你的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 

不過還好改變你的表纔能有正確的數據類型。

+0

謝謝!就是這樣,我的'時間戳'列是一個文本值。 -Ulises –

相關問題