我将假设 12 是 month,而 3 是 day,因为您没有指定。另外,您说您想要HH:MM:SS,但您的示例中没有秒数,所以我不知道您将如何将它们放入其中。在您的示例中,我还将8:37pm 更改为8:37am 以尝试这两种情况。
查询:
select concat_ws(' ', concat_ws('-', yr, month, day)
, concat_ws(':', hour, minutes)) date_time
from (
select yr
, case when length(month) < 2 then concat('0', month) else month end as month
, case when length(day) < 2 then concat('0', day) else day end as day
, case when instr(minutes, 'pm') > 0 then cast(hour+12 as int)
when instr(minutes, 'am') > 0 and length(hour) < 2 then concat('0', hour)
else hour end as hour
, substr(minutes, 1, 2) minutes
from (
select ltrim(split(Month, '\\/')[1]) day
, split(Month, '\\/')[0] month
, split(year, ' ')[0] yr
, split(split(year, ' ')[2], '\\:')[0] hour
, split(split(year, ' ')[2], '\\:')[1] minutes
from test.sample_data ) x ) y
输出:
date_time
2013-12-03 20:40
2013-12-03 20:39
2013-12-03 20:39
2013-12-03 20:38
2013-12-03 08:37