我有一个名为Date_of_Birth
的列,其中日期的格式为1978-07-23
。
我正在尝试使用此代码进行拆分,但它无效。
SELECT
case when split(Date_of_Birth,'\\-')[2] < 1900
THEN '1900-01-01 00:00:00'
else cast(from_unixtime(UNIX_TIMESTAMP(Date_of_Birth, 'M/d/yyyy')) as string) end as DOB
from rd_hr.wd_employees_history
答案 0 :(得分:0)
将日期转换为YYYY/MM/DD
后,您将获得“1900-01-01”和Date_of_Birth之间的最大值:
SELECT
greatest(from_unixtime(UNIX_TIMESTAMP(Date_of_Birth, 'MM/dd/yyyy')), '1900-01-01 00:00:00') AS DOB
FROM rd_hr.wd_employees_history
按原样投出日期将返回NULL
,请参阅:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-TimestampstimestampTimestamps