Sql 将字符转换为日期配置单元

Sql 将字符转换为日期配置单元,sql,date,hive,type-conversion,Sql,Date,Hive,Type Conversion,我需要在1列日期中包含2列字符。 我试过: INSERT INTO tb_teste PARTITION (dt_originacao_fcdr) SELECT tp_registro_fcdr, seq_registro_fcdr, tp_cdr_fcdr, dt_atendimento_fcdr, date_dt_atendimento_fcdr, hr_atendimento_fcdr, timestamp(from_unixtime(unix_timestamp(CONCAT(dt_at

我需要在1列日期中包含2列字符。 我试过:

INSERT INTO tb_teste PARTITION (dt_originacao_fcdr)
SELECT
tp_registro_fcdr,
seq_registro_fcdr,
tp_cdr_fcdr,
dt_atendimento_fcdr,
date_dt_atendimento_fcdr,
hr_atendimento_fcdr,
timestamp(from_unixtime(unix_timestamp(CONCAT(dt_atendimento_fcdr, hr_atendimento_fcdr), 'yyyyMMddHHmmss')), "yyyy-MM-dd HH:mm:ss") as date_hr_atendimento_fcdr,
duracao_atend_fcdr,
hr_originacao_fcdr,
duracao_total_fcdr,
duracao_chamada_tarifada_fcdr,
st_chamada_fcdr,
fim_sel_orig_fcdr,
numero_a_fcdr,
tp_numero_a_fcdr,
numero_b_fcdr,
tp_numero_b_fcdr,
numero_b_orig_fcdr,
numero_c_fcdr,
tp_numero_c_fcdr,
tp_trafego_fcdr,
esn_fcdr,
central_fcdr,
erb_fcdr,
tp_erb_fcdr,
face_erb_inici_fcdr,
erb_final_fcdr,
face_erb_final_fcdr,
erb_original_fcdr,
imsi_fcdr,
imei_fcdr,
tecnologia_fcdr,
cd_oper_ass_a_fcdr,
cd_oper_ass_b_fcdr,
cgi_fcdr,
nu_tlfn_fcdr,
tp_tlfn_fcdr,
tp_tarifa_fcdr,
ident_num_a_fcdr,
ident_num_b_fcdr,
cd_prestadora_fcdr,
cna_orig_ar_erb_fcdr
FROM tb_op_nor;
结果:日期:fcdr 2019-03-03

包含时间和日期的列不为null或为空。 例如:

时区:巴西


我需要在同一列中显示日期和时间。

您可以
concat
两个字段,然后
unix\u timestamp
并使用
from\u unixtimestamp
函数格式化输出时间戳

with cte as (select stack(1,"20190303","131615") as (dt,hr)) --sample data
select 
timestamp( --cast to timestamp
        from_unixtime(unix_timestamp(concat(dt,hr),'yyyyMMddHHmmss'),"yyyy-MM-dd HH:mm:ss") --concat and change the format
        ) 
from cte
输出:

2019-03-03 13:16:15.0

如果您想将巴西时间转换为UTC时间,或者反过来转换为UTC时间,请使用。

请以表格格式添加输入和预期输出。这个链接可能会有帮助:谢谢,舒。我尝试了以下方法:
CAST(时间戳(从unixtime(unix)时间戳(CONCAT(dt\u atendicato\u fcdr,hr\u atendicato\u fcdr),'yyyyymmddhhmmss'),“yyyy-MM-dd HH:MM:ss”)转换为date\u hr\u atendicato\u fcdr
,但失败:外部输入',在基本类型规范中预期接近'as'(状态=42000,代码=40000)。你能帮帮我吗?@LetíciaBoniottiFerreira,试试这个
时间戳(从unixtime(unix\u时间戳)(CONCAT(dt\u atendicato\u fcdr,hr\u atendicato\u fcdr),'yyyyymmddhhmmss'),“yyyy-MM-dd HH:MM:ss”)作为日期,hr\u atendicato\u fcdr
,timestamp()表示我们在这里投时间戳!,无需再次使用cast()。现在,它可以工作了。但是,我的输出只是日期,没有时间。日期\u hr\u atendimento\u fcdr->2019-03-03@LetíciaBoniottiFerreira,你能用你的select语句和样本数据更新这个问题吗?好的。样本数据存在问题。