我们必须将greenplumsql迁移到hivesql,如下所示,请帮助我们。
to_date(b.birthday,'yyyymmddhh24miss') extract(year from age(iDATE, to_date(b.birthday,'yyyymmddhh24miss')))
上面的两条语句需要将sql转换为hive。请帮帮我。配置单元版本:3.1.x
nue99wik1#
相当于 to_date(b.birthday,'yyyymmddhh24miss') 是
to_date(b.birthday,'yyyymmddhh24miss')
from_unixtime(unix_timestamp(b.birthday,'yyyyMMddHHmmss'))
然而,我不明白这一点 extract(year from age(iDATE, to_date(b.birthday,'yyyymmddhh24miss'))) . 你需要不同的出生日期和出生日期吗?如果是,您可以使用以年为单位获取日期差异。
extract(year from age(iDATE, to_date(b.birthday,'yyyymmddhh24miss')))
datediff(iDate,from_unixtime(unix_timestamp(b.birthday,'yyyyMMddHHmmss')) )/365
Hive也有 extract (year from datetimestamp) 功能。
extract (year from datetimestamp)
fruv7luv2#
提取时间戳的另一种方法是使用regexp\u replace:
regexp_replace(b.birthday,'^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})$','$1-$2-$3 $4:$5:$6')
年龄单位为:
cast(datediff(current_date, regexp_replace(b.birthday,'^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})$','$1-$2-$3 $4:$5:$6') )/365.25 as int)
2条答案
按热度按时间nue99wik1#
相当于
to_date(b.birthday,'yyyymmddhh24miss')
是然而,我不明白这一点
extract(year from age(iDATE, to_date(b.birthday,'yyyymmddhh24miss')))
. 你需要不同的出生日期和出生日期吗?如果是,您可以使用以年为单位获取日期差异。
Hive也有
extract (year from datetimestamp)
功能。fruv7luv2#
提取时间戳的另一种方法是使用regexp\u replace:
年龄单位为: