SQL 没有分隔符的日期处理(比如20220101)
主要是将没有带任何分隔符的日期,比如20220101,将其处理为2022-01-01
(1)MySQL
select date_format('20220101','%Y-%m-%d')
(2)hive sql
select to_date(from_unixtime(unix_timestamp('20220101','yyyyMMdd')))
hive 再增加一个精确是毫秒的例子:
如日期是下面的20230907,231834078
select *,from_unixtime(unix_timestamp(concat(date,'',SUBSTR(time,1,6)),'yyyyMMddHHmmss'),'yyyy-MM-dd HH:mm:ss') from xxx limit 3
浙公网安备 33010602011771号