0

我正在尝试使用以下代码从我的查询结果创建一个新表,同时在同一列中有两种不同的日期格式(在推文表中格式化为文本):

Create Table tweets_adj
select
t.fullname as company_name,
t.`user` as twitter_user_name,
t.id as tweet_id,
cast(t.likes as unsigned int) as likes,
cast(t.replies as unsigned int) as replies,
cast(t.retweets as unsigned int) as retweets,

case 
    when right(t.`text`,1)="'" and left(t.text, 2) = "b'" then left(replace(t.`text`, "b'", ""), length(replace(t.`text`, "b'", ""))-1)
    when right(t.`text`,1)='"' and left(t.text, 2) = 'b"' then left(replace(t.`text`, 'b"', ''), length(replace(t.`text`, 'b"', ''))-1)    
     else t.`text` end as content,

case 
    when STR_TO_DATE(t.timestamp, '%Y.%m.%d %H:%i:%s') is null
        then STR_TO_DATE(t.timestamp, '%d.%m.%Y %H:%i') 
        else STR_TO_DATE(t.timestamp, '%Y-%m-%d %H:%i:%s') 
end as timestamp,
t.url,
t.hashtags
from tweets t
limit 1000;

我必须在列时间戳中排序时间戳:20.08.2014 20:17 2014-03-10 02:19:02

我想将它们统一为一种日期格式(首选非特定格式)并将它们以正确的格式保存为日期,然后将整个选择导出到新查询中。

不幸的是,我收到一个错误:

日期时间值不正确:“20.08.2014 20:17:00”

我也发现了这个问题,但我太初学者了,无法理解该解决方案。

表推文看起来像这样 - 所有列都格式化为文本,例如 fullnameTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci', (...) timestampTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci', (...)

非常感谢任何帮助-谢谢!

4

0 回答 0