select case
when month(to_date(from_unixtime(unix_timestamp('20220713','yyyyMMdd'),'yyyy-MM-dd'))) > month('2000-07-14')
then (year(to_date(from_unixtime(unix_timestamp('20220713','yyyyMMdd'),'yyyy-MM-dd'))) - year('2000-07-14') -1) + 1
when month(to_date(from_unixtime(unix_timestamp('20220713','yyyyMMdd'),'yyyy-MM-dd'))) = month('2000-07-14')
and day(to_date(from_unixtime(unix_timestamp('20220713','yyyyMMdd'),'yyyy-MM-dd'))) >= day('2000-07-14')
then (year(to_date(from_unixtime(unix_timestamp('20220713','yyyyMMdd'),'yyyy-MM-dd'))) - year('2000-07-14') -1) + 1
else year(to_date(from_unixtime(unix_timestamp('20220713','yyyyMMdd'),'yyyy-MM-dd'))) - year('2000-07-14') -1
end as age;
Hive 根据生日计算年龄
最新推荐文章于 2024-07-15 02:56:20 发布