MySQL-非法混合使用排序规则(拉丁文1_瑞典语u ci implicit)和(utf8_general_ci可强制操作';=';
当我执行下面的查询时,会出现以下错误: 错误代码:1267.操作“=”的排序规则(拉丁文1\u瑞典文ci,隐式)和(utf8\u通用词ci,可强制)的非法混合 如果您需要此代码背后的背景信息,请参见以下说明:MySQL-非法混合使用排序规则(拉丁文1_瑞典语u ci implicit)和(utf8_general_ci可强制操作';=';,mysql,mysql-workbench,mysql-error-1267,Mysql,Mysql Workbench,Mysql Error 1267,当我执行下面的查询时,会出现以下错误: 错误代码:1267.操作“=”的排序规则(拉丁文1\u瑞典文ci,隐式)和(utf8\u通用词ci,可强制)的非法混合 如果您需要此代码背后的背景信息,请参见以下说明: 我将“facebook\u insight”表排序规则设置为:“utf8\u general\u ci”,但仍然出现错误。有人能帮我吗 MySQL查询: CREATE VIEW `facebook_insights` AS SELECT t1.id , t1.timest
我将“facebook\u insight”表排序规则设置为:“utf8\u general\u 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或timestamp
中的任何一个。它可能是varchar
或text
因此,当您尝试将INTERVAL 1 DAY
添加到非时间类型的值时,会出现错误
您必须将时间戳
列转换为任何日期、日期时间或时间戳
数据类型
作为快速解决方案,您可以在查询中使用STR\u TO\u 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
但是最好修改您的表以获得正确的数据类型。正如我从您的中猜到的,时间戳
列的类型不是日期、日期时间或时间戳
。它可能是varchar
或文本
因此,当您尝试将INTERVAL 1 DAY
添加到非时间类型的值时,会出现错误
您必须将时间戳
列转换为任何日期、日期时间或时间戳
数据类型
作为快速解决方案,您可以在查询中使用STR\u TO\u 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
但是最好修改您的表以获得正确的数据类型。排序规则问题不在表中。它是在间隔1天的情况下,您可能必须更改它的排序规则。您的数据库的默认排序规则是什么?@Sloarthrasher,我的数据库的默认排序规则是“latin1-默认排序规则”。排序规则问题不在选项卡中le.间隔为1天,您可能必须更改它的排序规则。您的数据库的默认排序规则是什么?@Sloarthrasher,我的数据库的默认排序规则是“latin1-默认排序规则”。谢谢!就是这样,我的“timestamp”列是一个文本值。-Ulises谢谢!就是这样,我的“timestamp”列是一个文本值。-Ulises